C# WINFORM项目中使用XPTable控件(XPTable控件使用说明一)

C# WINFORM项目中使用XPTable控件(XPTable控件使用说明一),第1张

我从MFC开始就一直使用ListView控件,直到前不久开发“汽车保养里程碑”工具才找到XPTable,用起来很方便的一个数据表展示控件,可惜网上说明不多,我来加一篇吧。


XPTable 包含三个组件:

XPTable has three main components:
 

  • Table
  • ColumnModel - the collection of Columns displayed in the Table
  • TableModel - the collection of Rows and Cells that contain the data displayed in the Table

在VS2019中从NuGet获取XPTable控件:

把三个组件拖到界面上

 在table属性中把column和model都关联上。


 控件也可以动态创建,比如下面代码:

// create a new Table, ColumnModel and TableModel
Table table = new Table();
ColumnModel columnModel = new ColumnModel();
TableModel tableModel = new TableModel();
 
// set the Table's ColumModel and TableModel
table.ColumnModel = columnModel;
table.TableModel = tableModel;
 
// add some Columns to the ColumnModel
columnModel.Columns.Add(new TextColumn("Text"));
columnModel.Columns.Add(new CheckBoxColumn("CheckBox"));
columnModel.Columns.Add(new ButtonColumn("Button"));
 
// add some Rows and Cells to the TableModel
tableModel.Rows.Add(new Row());
tableModel.Rows[0].Cells.Add(new Cell("Text 1"));
tableModel.Rows[0].Cells.Add(new Cell("CheckBox 1", true));
tableModel.Rows[0].Cells.Add(nnewew Cell("Button 1"));
tableModel.Rows.Add(new Row());
tableModel.Rows[1].Cells.Add(new Cell("Text 2"));
tableModel.Rows[1].Cells.Add(new Cell("CheckBox 2", false));
tableModel.Rows[1].Cells.Add(new Cell("Button 2"));

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/578491.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-11
下一篇2022-04-11

发表评论

登录后才能评论

评论列表(0条)

    保存