本示例隐藏在现有 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 属性