G
Guest
I am trying to bind a DataGrid Control (named DataGrid1) to an array list
containing elements of a sturcture type (named TestDataGrid). From what I've
read, it appears possible but the following code doesn't show the data nor
the column headings in the DataGrid control:
Public Structure TestDataGrid
Public Col1 As String
Public Col2 As String
End Structure
public ar As ArrayList = New ArrayList
Sub DisplayDatainGrid(dGrid as DataGrid)
Dim j As TestDataGrid
j.Col1 = "AAA" : j.Col2 = "BBB"
ar.Add(j)
j.Col1 = "111" : j.Col2 = "222"
ar.Add(j)
Dim ts1 As New DataGridTableStyle
ts1.MappingName = "TestDataGrid"
Dim c1 As New DataGridTextBoxColumn
c1.MappingName = "Col1"
c1.HeaderText = "Column1"
c1.Width = 100
ts1.GridColumnStyles.Add(c1)
Dim c2 As New DataGridTextBoxColumn
c2.MappingName = "Col2"
c2.HeaderText = "Column2"
c2.Width = 100
ts1.GridColumnStyles.Add(c2)
dGrid.TableStyles.Add(ts1)
dgrid.DataSource = ar
end sub
containing elements of a sturcture type (named TestDataGrid). From what I've
read, it appears possible but the following code doesn't show the data nor
the column headings in the DataGrid control:
Public Structure TestDataGrid
Public Col1 As String
Public Col2 As String
End Structure
public ar As ArrayList = New ArrayList
Sub DisplayDatainGrid(dGrid as DataGrid)
Dim j As TestDataGrid
j.Col1 = "AAA" : j.Col2 = "BBB"
ar.Add(j)
j.Col1 = "111" : j.Col2 = "222"
ar.Add(j)
Dim ts1 As New DataGridTableStyle
ts1.MappingName = "TestDataGrid"
Dim c1 As New DataGridTextBoxColumn
c1.MappingName = "Col1"
c1.HeaderText = "Column1"
c1.Width = 100
ts1.GridColumnStyles.Add(c1)
Dim c2 As New DataGridTextBoxColumn
c2.MappingName = "Col2"
c2.HeaderText = "Column2"
c2.Width = 100
ts1.GridColumnStyles.Add(c2)
dGrid.TableStyles.Add(ts1)
dgrid.DataSource = ar
end sub