Infragistics WinGrid绑定动态数据
Infragistics WinGrid是Infragistics Professional产品里Windows Form平台下的一个表格控件,该产品几乎可以实现数据表格展示的所有功能,数据绑定,增加,删除,更新,排序,分组等,并且产品提供了各种事例和帮助文档,帮助开发人员在最短时间内上手,这里我们简单介绍下该产品如果绑定使用代码产生的数据。
1. 首先我们创建一个新的桌面应用程序,直接从IDE的工具箱里拖拽UltraButton和UltraGrid控件到窗体上,然后在Button单击事件里添加如下代码:
private void ultraButton1_Click(object sender, EventArgs e)
{
// Declare a DataTable to contain the program generated data
DataTable dataTable = new DataTable("TableTest");
// Create and add a CustomerID column
DataColumn colWork = new DataColumn("CustomerID", System.Type.GetType("System.Int32"));
dataTable.Columns.Add(colWork);
// Add CustomerID column to key array and bind to DataTable
DataColumn[] Keys = new DataColumn[1];
Keys[0] = colWork;
dataTable.PrimaryKey = Keys;
// Create and add a CustomerName column
colWork = new DataColumn("CustomerName", System.Type.GetType("System.String"));
colWork.MaxLength = 50;
dataTable.Columns.Add(colWork);
// Create and add a LastOrderDate column
colWork = new DataColumn("LastOrderDate", System.Type.GetType("System.DateTime"));
dataTable.Columns.Add(colWork);
// Add a row
DataRow row = dataTable.NewRow();
row["CustomerID"] = 1;
row["CustomerName"] = "Johns Widgets";
row["LastOrderDate"] = System.DateTime.Now;
dataTable.Rows.Add(row);
// Add another row
row = dataTable.NewRow();
row["CustomerID"] = 2;
row["CustomerName"] = "Freds Thingamagigs";
row["LastOrderDate"] = System.DateTime.Now.AddDays(-101);
dataTable.Rows.Add(row);
// Bind the table to the grid
this.ultraGrid1.DataSource = dataTable;
}
运行事例,该实例的运行效果图如下: