Private Sub FormatHGGrid()
With Me.grdHotelGroups
.DataSource = HotelGroupData
.DataMember = "tblHotelGroup"
.BorderStyle = BorderStyle.None
.CaptionFont = New Font("Tahoma", 10.0!, FontStyle.Bold)
.CaptionText = "Hotel Groups"
.Font = New Font("Tahoma", 8.0!)
End With
Put as much of the formatting as possible here.
Dim grdTableStyle1 As New DataGridTableStyle()
With grdTableStyle1
.HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
.RowHeadersVisible = False
Do not forget to set the MappingName property.
Without this, the DataGridTableStyle properties
and any associated DataGridColumnStyle objects
will have no effect.
.MappingName = "tblHotelGroup"
.PreferredColumnWidth = 125
.PreferredRowHeight = 15
End With
Format each column that you want to appear in the DataGrid.
In most cases, the DataGridTextBoxColumn class is appropriate.
However, you can also use the DataGridBoolColumn class. Both
of these extend the MustInherit DataGridColumnStyle class. Notice
that the column style properties available to you are more limited
than those for the table style. For example, you cannot change
the color of an individual column.
Dim grdColStyle1 As New DataGridTextBoxColumn()
With grdColStyle1
.HeaderText = ""
.MappingName = "intHotelGroupID"
.Width = 0
.ReadOnly = True
End With
Dim grdColStyle2 As New DataGridTextBoxColumn()
With grdColStyle2
.HeaderText = "Hotel Groups"
.MappingName = "vstrHotelGroupName"
.Width = Me.grdHotelGroups.Width
End With
Add the style objects to the table styles collection of
column styles. Without this the styles do not take effect.
grdTableStyle1.GridColumnStyles.AddRange(New DataGridColumnStyle() {grdColStyle2})
grdHotelGroups.TableStyles.Add(grdTableStyle1)
End Sub