How can I populate a list of array into a datagrid ?
I tried adding the header but it doesnt seems to be working as well.
I tried adding the header but it doesnt seems to be working as well.
VB.NET:
With grdProducts
.BackColor = Color.GhostWhite
.BackgroundColor = Color.Lavender
.BorderStyle = BorderStyle.None
.CaptionBackColor = Color.RoyalBlue
.CaptionFont = New Font("Tahoma", 10.0!, FontStyle.Bold)
.CaptionForeColor = Color.Bisque
.CaptionText = "Kmart Order Forcast"
.Font = New Font("Tahoma", 8.0!)
.ParentRowsBackColor = Color.Lavender
.ParentRowsForeColor = Color.MidnightBlue
End With
Dim grdTableStyle1 As New DataGridTableStyle()
With grdTableStyle1
.AlternatingBackColor = Color.GhostWhite
.BackColor = Color.GhostWhite
.ForeColor = Color.MidnightBlue
.GridLineColor = Color.RoyalBlue
.HeaderBackColor = Color.MidnightBlue
.HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
.HeaderForeColor = Color.Lavender
.SelectionBackColor = Color.Teal
.SelectionForeColor = Color.PaleGreen
' Do not forget to set the MappingName property.
' Without this, the DataGridTableStyle properties
' and any associated DataGridColumnStyle objects
' will have no effect.
.PreferredColumnWidth = 125
.PreferredRowHeight = 15
End With
Dim grdColStyle1 As New DataGridTextBoxColumn()
With grdColStyle1
.HeaderText = "ID"
.MappingName = "ProductID"
.Width = 50
End With
Dim grdColStyle2 As New DataGridTextBoxColumn()
With grdColStyle2
.HeaderText = "Name"
.MappingName = "ProductName"
End With
Dim grdColStyle3 As New DataGridTextBoxColumn()
With grdColStyle3
.HeaderText = "Price"
.MappingName = "UnitPrice"
.Width = 75
.ReadOnly = True
End With
Dim grdColStyle4 As New DataGridTextBoxColumn()
With grdColStyle4
.HeaderText = "# In Stock"
.MappingName = "UnitsInStock"
.Width = 75
.Alignment = HorizontalAlignment.Center
End With
grdTableStyle1.GridColumnStyles.Add(grdColStyle1)
grdTableStyle1.GridColumnStyles.Add(grdColStyle2)
grdTableStyle1.GridColumnStyles.Add(grdColStyle3)
grdTableStyle1.GridColumnStyles.Add(grdColStyle4)
grdProducts.TableStyles.Add(grdTableStyle1)