本示例隐藏在现有 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 和 DataColumn 对象还具有字符串类型的名称。若要查找该表的名称,请检查该表的 TableName 属性。若要查找 DataColumn 的名称,请检查该列的 ColumnName 属性。
隐藏数据列的另一种方法是,创建 DataGridColumnStyle 对象并将其添加到 GridColumnStyles 集合中。
此示例展示了如何在Windows Forms的DataGrid控件中隐藏DataTable的特定列,具体操作涉及检查DataTable的TableName和DataColumn的ColumnName属性。

8415

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



