XPTable 的使用方法 【Z】

下载XPTable提供示例:下载  

    当我们使用C#开发Windows应用程序,通常都用到DataGridView控件,毫无疑问,DataGrideView控件只提供了一些基本能满足我们使用的功能,而且如果在DataGridView里添加CheckBox、下拉框、等等相关控件时,使用起来十分麻烦,如果阁下觉得使用微软件提供的DataGridView十分麻烦时,这里小弟推荐 XPTable 给大家使用,XPTable Codeproject 提供开源的第三方控件,其功能十分强大。截图可以看出XPTable里可以添加各式各样的控件。

     XPTable 提供的几个Demo可以点击这里下载:下载Demo.

     如下是介绍我在项目里使用XPTable的一些分享:

     1、先下载XPTable编译文件:XPTable.DLL。(点击下载)

     2、将XPTable,添加到工具箱里,添加完成后将有三个控件:Table、TableModel、ColumnModel

     添加到工具箱的方法:     A、在工具箱上点右键选择“添加选项卡”(写上自己想写的名字,例如:第三控件),B、再在第三控件 这个选项卡上右键点“选择项”

在出现的窗体上点浏览,到自己的.dll文件,选择该文件。)

     如图:

  3、将相应三个控件添加到Main窗口里如图

  4、写代码初始化XPTable 如下

 string table = this.TableName;
           if (string.IsNullOrEmpty(table)) return;
           DataTable dt = GetDBInfoBLL.GetTBConfiguration(table);
           dt.Columns.Remove("表名");
           dt.Columns.Remove("默认值");
           dt.Columns.Remove("主键");
           dt.Columns.Remove("表说明");
           dt.Columns.Remove("字段序号");
           dt.Columns.Add("添加说明", Type.GetType("System.String"));
           dt.Columns.Add("表头说明", Type.GetType("System.String"));
           ///选择框 添加
           CheckBoxColumn checkbox_Add = new CheckBoxColumn("添加", 80);
           ///选择框 修改
           CheckBoxColumn checkbox_Update = new CheckBoxColumn("修改", 80);
           ///选择框 列表
           CheckBoxColumn checkbox_List = new CheckBoxColumn("列表", 80);
           ///选择框  搜索
           CheckBoxColumn checkbox_Search = new CheckBoxColumn("搜索", 80);
           //下拉框
           ComboBoxColumn combobox_search = new ComboBoxColumn("搜索类型", 80);
           ComboBoxCellEditor searchEditor = new ComboBoxCellEditor();
           searchEditor.DropDownStyle = DropDownStyle.DropDownList;
           searchEditor.Items.AddRange(new string[] { "大于", "小于", "等于", "相同", "Other" });
           combobox_search.Editor = searchEditor;
           //下拉框 验证
           ComboBoxColumn combobox_Verificat = new ComboBoxColumn("验证", 100);
      
           ComboBoxCellEditor VerificatEditor = new ComboBoxCellEditor();
           VerificatEditor.DropDownStyle = DropDownStyle.DropDownList;
           VerificatEditor.Items.AddRange(new string[] { "不为空", "Classical", "Comedy", "Rock", "Other" });
           combobox_Verificat.Editor = VerificatEditor;
           //字段说明
           TextColumn text_name = new TextColumn("字段", 100);
           //字段说明
           TextColumn text_desc = new TextColumn("字段说明", 154);
           //字段 标识
           TextColumn text_Ident = new TextColumn("标识", 40);
           //字段 类型
           TextColumn text_type = new TextColumn("类型", 62);
           //字段  长度
           TextColumn text_Length = new TextColumn("长度", 50);
           //字段 允许为空
           TextColumn text_allowEmpty = new TextColumn("为空", 50);
           //字段  添加说明
           TextColumn text_addDesc = new TextColumn("添加说明", 130);
           //字段,表头
           TextColumn text_tableHeader = new TextColumn("表头", 130);
           this.table.ColumnModel = new ColumnModel(new Column[] {
                                                                      //字段名
                                                                       text_name,
                                                                       //添加选择框
                                                                      checkbox_Add,
                                                                       //添加验证下拉框
                                                                      combobox_Verificat,
                                                                    //修改选择框
                                                                      checkbox_Update,
                                                                      //列表选择框
                                                                      checkbox_List,
                                                                      //搜索选择框
                                                                      checkbox_Search,
                                                                      //搜索类型下拉框
                                                                      combobox_search,
                                                                      //字段说明·
                                                                      text_desc,
                                                                       //标识
                                                                      text_Ident,
                                                                       //类型
                                                                      text_type,
                                                                       //长度
                                                                      text_Length,
                                                                       //允许为空
                                                                      text_allowEmpty,
                                                                       //添加说明
                                                                      text_addDesc,
                                                                       //表头说明
                                                                      text_tableHeader
            });
           //行数
           Row[] RowList = new Row[dt.Rows.Count];
           for (int i = 0; i < dt.Rows.Count; i++)
           {
               //字段名
               string name = dt.Rows[i][0].ToString();
               if (string.IsNullOrEmpty(name)) continue;
               //字段说明
               string fieldDesc = dt.Rows[i][1].ToString();
               //标识
               string Ident = dt.Rows[i][2].ToString();
               //字段类型
               string fieldType = dt.Rows[i][3].ToString();
               //字段长度
               string fieldLength = dt.Rows[i][4].ToString();
               //允许为空
               string allowEmpty = dt.Rows[i][5].ToString();
               //添加说明
               string addDesc = dt.Rows[i][6].ToString();
               //表头说明
               string tableHeader = dt.Rows[i][7].ToString();
               Row r = new Row(new Cell[]{   
                                                             //名称
                                                              new Cell(name),
                                                              //添加选择框
                                                              new Cell(name,true),
                                                              //添加验证下拉框
                                                              new Cell(""),
                                                              //修改选择框
                                                              new Cell(name,true),
                                                                //列表选择框
                                                              new Cell(name,true),
                                                               //搜索选择框
                                                              new Cell(name,false),
                                                                //搜索类型下拉框
                                                              new Cell(""),
                                                               //字段说明·
                                                              new Cell(fieldDesc),
                                                              //标识
                                                              new Cell(Ident),
                                                               //类型
                                                              new Cell(fieldType),
                                                                //长度
                                                              new Cell(fieldLength),
                                                              //允许为空
                                                              new Cell(allowEmpty),
                                                               //添加说明
                                                              new Cell(addDesc),
                                                               //表头说明
                                                              new Cell(tableHeader)                                                                            
                                                        });
               RowList[i] = r;
           }
           this.table.TableModel = new TableModel(RowList);
           this.table.BeginEditing += new XPTable.Events.CellEditEventHandler(table_BeginEditing);
           this.table.TableModel.RowHeight = 21;
           this.table.EndUpdate();
info.AddDes =this.table.TableModel.Rows[i].Cells[12].Text; info.TableHeader =this.table.TableModel.Rows[i].Cells[13].Text; InfoList.Add(info); }

 

   小弟用XPTable做的Table截图如下:

InfoList = new List<CreateInfo>();
            for (int i = 0; i < table.RowCount; i++)
            {
                CreateInfo info = new CreateInfo();
                info.Field = this.table.TableModel.Rows[i].Cells[0].Text;
                     
                info.Add =this.table.TableModel.Rows[i].Cells[1].Checked;
                info.Verificat =this.table.TableModel.Rows[i].Cells[2].Text;
                info.Update =this.table.TableModel.Rows[i].Cells[3].Checked;
                info.FieldList =this.table.TableModel.Rows[i].Cells[4].Checked;
                info.SearchField =this.table.TableModel.Rows[i].Cells[5].Checked;
                info.SearchType =this.table.TableModel.Rows[i].Cells[6].Text;
                info.FieldDes =this.table.TableModel.Rows[i].Cells[7].Text;
                info.Ident =this.table.TableModel.Rows[i].Cells[8].Text;
                info.FieldType =this.table.TableModel.Rows[i].Cells[9].Text;
                info.FieldLength =this.table.TableModel.Rows[i].Cells[10].Text;
                info.AllowNull =this.table.TableModel.Rows[i].Cells[11].Text;
                info.AddDes =this.table.TableModel.Rows[i].Cells[12].Text;
                info.TableHeader =this.table.TableModel.Rows[i].Cells[13].Text;
                InfoList.Add(info);
            }

大家可以根据自己的需要来做...有问题可以留言讨论。

原帖地址:http://www.3api.com/view/42.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
XPTable的大名,想必C#开发的人都有所耳闻,使用下来确实强大,在表格中添加下拉列表、进度条、图标等非常容易,灵活方便。 XPTable最重要的是开源,可根据自己的需要修改,有bug也可想办法解决,我就对其进行了若干处改进,使其更好用了。源代码写的非常标准,架构设计也很值得借鉴,研读源代码也是个学习提高的过程。真心感谢将如此完美的代码公开分享的人,最为点滴回报,也将自己修改后的源码放出,供大家参考,和原作者的贡献比起来,我这点小小的修改就如沧海一粟,不足为道了。 我修改过的代码和解决的问题列示如下: 1、...\Models\Table.cs Line 2118,2153 解决问题:否则在某些情况下(任意调整窗口大小,XPTable的Anchor设置为随窗口大小自适应调整)会抛System.ArgumentOutOfRangeException异常,vScrollBar.LargeChange不能小于0 2、...\Models\Table.cs Line 5598,5606 解决问题:在列头Resizing状态下双击鼠标,应根据该列数据中最长的一行调整当前列宽度,目前仅对TextColumn和NumberColumn有效 3、...\Models\Table.cs Line 6134 解决问题:在列头Resizing状态下单击鼠标,避免OnMouseUp激发列宽的调整。应该双击或者调整宽度后才能激发 4、...\Models\Table.cs Line 6373 解决问题:根据原代码,如果Table允许多选,选中多行后,点鼠标右键将自动选择鼠标所在行,修改后,多选的行依然选中 这个问题借鉴了“恶猫的尾巴”的代码:http://emao.me/tag/XpTable/,在此感谢! 5、...\Models\Table.cs Line 6627 解决问题:鼠标在列头为Resizing图标时,移动到数据区域不会自动变为默认图标 6、...\Models\Table.cs Line 7229 解决问题:解决列头的对齐方式始终是靠左的问题 7、...\Renderers\NumberCellRenderer.cs Line 661 解决问题:为了实现Table.cs的函数CalColumnWidth中实现对NumberColumn列格式化数据宽度的计算

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值