Datagrid refresh problem with new entries
In the application I am writing I open a dialog window for entry of
value pairs via combobox selections that are added to a grid on that
form. The items in the grid can be removed as well. The problem I am
having is when the window is closed and then re-opened an added item
row doesn't appear in the grid. If the window is closed and re-opened
the new row will appear.
Here is code from the Form Load event:
Dim tableStyle As New DataGridTableStyle
tableStyle.MappingName = "sample_area"
Dim column As New DataGridTextBoxColumn
column.MappingName = "district"
column.HeaderText = "District"
column.Width = 100
tableStyle.GridColumnStyles.Add(column)
column = New DataGridTextBoxColumn
column.MappingName = "subdistrict"
column.HeaderText = "SubDistrict"
column.Width = 100
tableStyle.GridColumnStyles.Add(column)
tableStyle.MappingName = "sample_area"
With grdAreas
.ColumnHeadersVisible = True
.TableStyles.Add(tableStyle)
End With
grdAreas.DataSource = gdsData.Tables("sample_area")
The Add Event:
Dim dr As System.Data.DataRow
dr = gdsData.Tables("sample_area").NewRow
dr.Item("year") = gstrCWTYear
dr.Item("sample") = gstrSampleNumber
dr.Item("district") = cboDistrict.Text
dr.Item("subdistrict") = cboSubdistrict.Text
gdsData.Tables("sample_area").Rows.Add(dr)
In the remove event I find the row in the dataset and issue a
gdsData.Tables("sample_area").Rows(rowIndex).Delete
The very first time the window is opened everything seems to work fine
but if the window is closed:
Private Sub btnOk_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnOk.Click
Me.Close()
End Sub
And then opened:
Dim f As New frmArea
f.ShowDialog()
The grid will not display a new "addition".
I have tried refresh but the only thing that seems to work is setting
the datasource of the grid to nothing and then set it back to the
dataset's datatable. This; however, just doesn't seem right.
Does anyone have any idea what I am doing wrong?
Date:Fri, 20 Jul 2007 17:11:11 -0000
Author:
|