您的位置:首页 > 其它

XPTable 的使用方法 【Z】

2012-12-24 18:22 211 查看


下载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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: