我正在使用C1FlexGrid
并将数据表设置为 c1flexgrid的数据源。现在我想通过代码将数据表的字段映射到 c1flexgrid 的列。请告诉我该怎么做。
答案 0 :(得分:4)
以编程方式在C1FlexGrid上创建列:
- 将AutoGenerateColumns设置为False
- 将列定义添加到C1FlexGridBase.Cols()集合。
- 将DataTable绑定到flexgrid
例如,
Private _dt As System.Data.DataTable
Private Sub LoadFlexGrid()
'create new table
_dt = New System.Data.DataTable("MyDataTable")
_dt.Columns.Add("CustomerId", GetType(Integer))
_dt.Columns.Add("CustomerName", GetType(String))
'populate it
_dt.Rows.Add(New Object() {12, "Joe"})
_dt.Rows.Add(New Object() {14, "Bob"})
'define column grid columns
Dim col1 As C1.Win.C1FlexGrid.Column
col1 = flex.Cols.Add()
col1.Name = "CustomerId"
col1.Caption = "Customer Id"
Dim col2 As C1.Win.C1FlexGrid.Column
col2 = flex.Cols.Add()
col2.Name = "CustomerName"
col2.Caption = "Name"
'bind the grid to it
flex.AutoGenerateColumns = False
flex.DataSource = _dt
End Sub