Private Sub Form1_Load(ByVal sender As System.Object,
_
ByVal e As System.EventArgs) Handles MyBase.Load
Me.SqlDataAdapter1.Fill(Me.DataSet11)
'Step
1: Create a DataGridTableStyle
' set
mappingname to table.
Dim tblstyle As New DataGridTableStyle()
tblstyle
.MappingName = "PRODUCT"
'Step
2: Create DataGridColumnStyle for each col
' we
want to see in the grid and in the
' order
that we want to see them.
'Discontinued.
Dim discontinuedCol As New DataGridBoolColumn()
discontinuedCol.MappingName
= "Discontinued"
discontinuedCol.HeaderText
= ""
discontinuedCol.Width
= 30
'turn
off tristate
discontinuedCol.AllowNull
= False
tblstyle
.GridColumnStyles.Add(discontinuedCol)
'Step
2: PrdID
Dim column As New DataGridTextBoxColumn()
column.MappingName
= "PrdID"
column.HeaderText
= "ID"
column.Width
= 30
tblstyle
.GridColumnStyles.Add(column)
'Step
2: PRdNAme
column
= New DataGridTextBoxColumn()
column.MappingName
= "PRdNAme"
column.HeaderText
= "Name"
column.Width
= 140
tblstyle
.GridColumnStyles.Add(column)
'Step
2: Qty
column
= New DataGridTextBoxColumn()
column.MappingName
= "Qty"
column.HeaderText
= "QuantityPerUnit"
tblstyle
.GridColumnStyles.Add(column)
'Step
2: Price
column
= New DataGridTextBoxColumn()
column.MappingName
= "Price"
column.HeaderText
= "UnitPrice"
tblstyle
.GridColumnStyles.Add(column)
'Step
2: Stock
column
= New DataGridTextBoxColumn()
column.MappingName
= "Stock"
column.HeaderText
= "UnitsInStock"
tblstyle
.GridColumnStyles.Add(column)
'Step
2: Order
column
= New DataGridTextBoxColumn()
column.MappingName
= "Order"
column.HeaderText
= "UnitsOnOrder"
tblstyle
.GridColumnStyles.Add(column)
'Step
2: Record
column
= New DataGridTextBoxColumn()
column.MappingName
= "Record"
column.HeaderText
= "ReorderLevel"
tblstyle
.GridColumnStyles.Add(column)
'Step
3: Add the tablestyles and all to the datagrid
Me.DataGrid1.TableStyles.Add(tableStyle)
End Sub
Figure 5 is
the DataGrid after adding the previous code. The columns should be exactly the
columns previously specified as needed, and the Discontinued column should
appear first.