M
Merlin
Why does the following only work once? If I put the grid code in a button
and click once the grid is populated, if I click the button a further times
the grid has no data! What I'm attempting to do below is put a Datatable
within a Dataset and show the results in the grid, then clear the Datatable
and Dataset and repopulate with new data.
Many thanks,
Merlin
Please note the code is simplified for example purpose; use of the Dataset
is so I can setup relational data .
'// The following code uses Microsofts standard DataGrid
'// Declarations Section
Dim dataset As New Dataset
Dim DT As New DataTable("DT")
Private row As DataRow = DT.NewRow()
'// Code to put data within grid
DT.Reset()
dataset.Reset()
Dim colWork As New DataColumn("Line", GetType(Integer))
colWork.ReadOnly = True
DT.Columns.Add(colWork)
Dim Keys(0) As DataColumn
Keys(0) = colWork
'DT.PrimaryKey = Keys
colWork = New DataColumn("Part", GetType(String))
DT.Columns.Add(colWork)
For i As Integer = 1 To 5
row = DT.NewRow()
row(0) = i.ToString
row(1) = ""
DT.Rows.Add(row)
Next
dataset.Tables.Add(DT)
DataGrid1.DataSource = dataset
and click once the grid is populated, if I click the button a further times
the grid has no data! What I'm attempting to do below is put a Datatable
within a Dataset and show the results in the grid, then clear the Datatable
and Dataset and repopulate with new data.
Many thanks,
Merlin
Please note the code is simplified for example purpose; use of the Dataset
is so I can setup relational data .
'// The following code uses Microsofts standard DataGrid
'// Declarations Section
Dim dataset As New Dataset
Dim DT As New DataTable("DT")
Private row As DataRow = DT.NewRow()
'// Code to put data within grid
DT.Reset()
dataset.Reset()
Dim colWork As New DataColumn("Line", GetType(Integer))
colWork.ReadOnly = True
DT.Columns.Add(colWork)
Dim Keys(0) As DataColumn
Keys(0) = colWork
'DT.PrimaryKey = Keys
colWork = New DataColumn("Part", GetType(String))
DT.Columns.Add(colWork)
For i As Integer = 1 To 5
row = DT.NewRow()
row(0) = i.ToString
row(1) = ""
DT.Rows.Add(row)
Next
dataset.Tables.Add(DT)
DataGrid1.DataSource = dataset