|
~~~~~~~~~~~~~~~~~~~~
Private Sub setMyDataGridTableStyleProperties (ByRef myDG as DataGrid)
' Use a table style object to apply custom formatting
‘ to the DataGrid.
Dim mydgTableStyle As New DataGridTableStyle()
Dim mygrdColStyle1, mygrdColStyle2, mygrdColStyle3,
mygrdColStyle4, mygrdColStyle5 As New & _
DataGridTextBoxColumn()
With mydgTableStyle
.AlternatingBackColor = Color.LightCoral
.BackColor = Color.LawnGreen
.ForeColor = Color.LightGray
.GridLineColor = Color.LightGreenrodYellow
.GridLineStyle = System.Windows.Forms.DataGridLineStyle.
.HeaderBackColor = Color. LightGray
.HeaderFont = New Font("Courier", 10.0!, FontStyle.Bold)
.HeaderForeColor = Color. LawnGreen
.LinkColor = Color.Teal
' Do not forget to set the MappingName property.
' Without this, the DataGridTableStyle properties
' and any associated DataGridColumnStyle objects
' will have no effect.
.MappingName = "Customers"
.SelectionBackColor = Color. LawnGreen
.SelectionForeColor = Color. LightGray
End With
' Use column style objects to apply formatting specific
‘ to each column of customer table.
With mygrdColStyle1
.HeaderText = "ID#"
.MappingName = "CustomerID"
.Width = 50
End With
With mygrdColStyle2
.HeaderText = "Last Name"
.MappingName = "NameLast"
.Width = 140
End With
With mygrdColStyle3
.HeaderText = "Address"
.MappingName = "Address1"
.Width = 180
End With
With mygrdColStyle4
.HeaderText = "State"
.MappingName = "State"
.Width = 30
End With
With mygrdColStyle5
.HeaderText = "Phone"
.MappingName = "Phone"
.Width = 70
End With
' Add the column style objects to the tables style's
‘ column styles collection. If you fail to do this the column
‘ styles will not apply.
mydgTableStyle.GridColumnStyles.AddRange _
(New DataGridColumnStyle() _
{ mygrdColStyle1, mygrdColStyle2,
mygrdColStyle3, mygrdColStyle4, mygrdColStyle5})
' Add the table style object to the DataGrid's table styles
' collection. Again, failure to add the style to the collection
' will cause the style to not take effect.
myDG.TableStyles.Add(mydgTableStyle)
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can see details on my Article 2
Benoy
Benoy
|
|
|
|
|
Private Sub setMyDataGridTableStyleProperties (ByRef myDG as DataGrid)
' Use a table style object to apply custom formatting
‘ to the DataGrid.
Dim mydgTableStyle As New DataGridTableStyle()
Dim mygrdColStyle1, mygrdColStyle2, mygrdColStyle3,
mygrdColStyle4, mygrdColStyle5 As New & _
DataGridTextBoxColumn()
With mydgTableStyle
.AlternatingBackColor = Color.LightCoral
.BackColor = Color.LawnGreen
.ForeColor = Color.LightGray
.GridLineColor = Color.LightGreenrodYellow
.GridLineStyle = System.Windows.Forms.DataGridLineStyle.
.HeaderBackColor = Color. LightGray
.HeaderFont = New Font("Courier", 10.0!, FontStyle.Bold)
.HeaderForeColor = Color. LawnGreen
.LinkColor = Color.Teal
' Do not forget to set the MappingName property.
' Without this, the DataGridTableStyle properties
' and any associated DataGridColumnStyle objects
' will have no effect.
.MappingName = "Customers"
.SelectionBackColor = Color. LawnGreen
.SelectionForeColor = Color. LightGray
End With
' Use column style objects to apply formatting specific
‘ to each column of customer table.
With mygrdColStyle1
.HeaderText = "ID#"
.MappingName = "CustomerID"
.Width = 50
End With
With mygrdColStyle2
.HeaderText = "Last Name"
.MappingName = "NameLast"
.Width = 140
End With
With mygrdColStyle3
.HeaderText = "Address"
.MappingName = "Address1"
.Width = 180
End With
With mygrdColStyle4
.HeaderText = "State"
.MappingName = "State"
.Width = 30
End With
With mygrdColStyle5
.HeaderText = "Phone"
.MappingName = "Phone"
.Width = 70
End With
' Add the column style objects to the tables style's
‘ column styles collection. If you fail to do this the column
‘ styles will not apply.
mydgTableStyle.GridColumnStyles.AddRange _
(New DataGridColumnStyle() _
{ mygrdColStyle1, mygrdColStyle2,
mygrdColStyle3, mygrdColStyle4, mygrdColStyle5})
' Add the table style object to the DataGrid's table styles
' collection. Again, failure to add the style to the collection
' will cause the style to not take effect.
myDG.TableStyles.Add(mydgTableStyle)
End Sub
You can see more details on my article 2.
Benoy
|
|
|
|