XPTABLE github
GitHub - schoetbi/XPTable: sourceforge.net XPTable clone with my patches
我从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"));