本示例隐藏在现有 Windows 窗体 DataGrid 控件中显示的 DataTable 对象的“X”列。
示例
Sub HideColumnOfDataSet()
Dim points As New System.Data.DataTable("Points")
points.Columns.Add(New DataColumn("X", GetType(Integer)))
points.Columns.Add(New DataColumn("Y", GetType(Integer)))
points.Rows.Add(New Object() {1, 2})
points.Rows.Add(New Object() {3, 5})
DataGrid1.DataSource = points
Dim tableStyle As New DataGridTableStyle
tableStyle.MappingName = "Points"
DataGrid1.TableStyles.Add(tableStyle)
DataGrid1.TableStyles("Points").GridColumnStyles("X").Width = 0
End Sub
编译代码
本示例需要:
- 一个 Windows 窗体。
- 名为 DataGrid1 的 DataGrid 控件。
如果数据源是 DataSet 对象,则将 DataGrid 的 DataMember 属性设置为该表的名称。
类型化数据集中的 DataTable 和 DataC

此示例展示了如何在Windows Forms的DataGrid控件中隐藏DataTable的特定列,具体操作涉及检查DataTable的TableName和DataColumn的ColumnName属性。
最低0.47元/天 解锁文章
1364

被折叠的 条评论
为什么被折叠?



