vb.net - 如何在 c1flexgrid 中通过代码设置 DataField 属性

标签 vb.net grid componentone

我正在使用 C1FlexGrid 并将数据表设置为 c1flexgrid 的 数据源。现在我想通过代码将数据表的字段映射到 c1flexgrid 的列。请告诉我该怎么做。

最佳答案

以编程方式在 C1FlexGrid 上创建列:
- 将 AutoGenerateColumns 设置为 False
- 添加列定义到 C1FlexGridBase.Cols() 集合。
- 将 DataTable 绑定(bind)到 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

关于vb.net - 如何在 c1flexgrid 中通过代码设置 DataField 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1845100/

相关文章:

windows - VB6 VisualBasic6 API 是否适用于 Windows 8?

twitter-bootstrap - Bootstrap 网格列相互重叠

vb.net - C1FlexGrid 从单元格复选框中获取值

wpf - WPF 的 ComponentOne : Text seems to render in the incorrect position?

c# - Visual Basic 中 |= 的等价物是什么?

.net - 使用多个文件作为资源管理器的参数打开程序一次

c# - 在 .NET 控制台应用程序中,是否可以让一行文本始终在控制台中保持可见?

html - 表单字段溢出 Bootstrap 表单

asp.net-mvc - 将参数传递给 Telerik asp.net mvc 网格

.net - 缺少 ComponentOne licenses.licx 文件