Array to Datagrid

winsonlee

Member
Joined
Jan 5, 2008
Messages
10
Programming Experience
Beginner
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.

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)
 
Hi


You are going to have to clarify what you mean by 'list of array'
 
tbh, i think you'd find it easier to just transfer the list(of whatever()) into a datatable, or use a datatable in the first place

something like:

VB.NET:
Dim dt as new datatable
foreach sa as string() in mylist
  dt.rows.add(sa)
next sa

mylist = nothing
sa = nothing

mygrid.datasource = dt
 
Back
Top