R
Ron L
All
I am working with a DataGrid and a form consisting of a number of text,
checkbox, combobox controls, all bound to the same datatable. When I click
on my "New" button, I create a new row, make it the current row, and allow
the user to make changes in the form. If the user desires to cancel, they
can click the "Cancel Changes" button. Here is where my problems start.
Once the Cancel Changes button is clicked, the bindings on the form appear
to be permanently lost until I close and re-open the form. I have attached
the relevant portions of the New and Cancel button Click Event routines as
well as a representative portion of the binding initializations. Note that
I only bind the controls at form startup.
Can anyone tell me what I am doing wrong here?
TIA
Ron L
Private Sub BtnNew_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles _btnNew.Click
....
' Create a new row in the data table and change the List Tab's
filter so that the new row is the selected item
Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource, DataTable)
Dim dr As DataRow = dt.NewRow
dr.Item("PPDID") = "NewPPD"
dt.Rows.Add(dr)
CType(cm.List, DataView).RowFilter = "PPDID = 'NewPPD'"
....
End Sub
Private Sub CancelChanges(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles _btnCancel.Click
Dim cm As CurrencyManager
Dim drv, newRow As DataRowView
Dim permLevel As Integer
Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource, DataTable)
dt.RejectChanges()
' reset the previously selected ID.
_listCtlr.SetCurrentRow(_listSelectedID)
drv = CType(cm.List,
DataView).Item(_ppdctlr.ListGrid.CurrentRowIndex)
permLevel = PermissionLevel(drv)
....
End Sub
Private Sub BindUserControls()
Dim dt As DataTable = _ppdctlr.ListGrid.DataSource
_txtPPDID.DataBindings.Add("text", dt, "PPDID")
_txtGlobalID.DataBindings.Add("text", dt, "GlobalID")
_txtDuplicateOf.DataBindings.Add("text", dt, "DuplicateOf")
_txtCPRRequestSubmitted.DataBindings.Add("text", dt,
"CPRRequestedDate")
_cbCPRRequired.DataBindings.Add("Checked", dt, "CPRRequired")
_cbDPRRequired.DataBindings.Add("Checked", dt, "DPRRequired")
_txtTitle.DataBindings.Add("text", dt, "Title")
_txtModDate.DataBindings.Add("text", dt, "ModifiedDate")
_cboType.DataBindings.Add("text", dt, "Type")
_cboProblemArea.DataBindings.Add("text", dt, "ProblemArea")
....
End Sub
I am working with a DataGrid and a form consisting of a number of text,
checkbox, combobox controls, all bound to the same datatable. When I click
on my "New" button, I create a new row, make it the current row, and allow
the user to make changes in the form. If the user desires to cancel, they
can click the "Cancel Changes" button. Here is where my problems start.
Once the Cancel Changes button is clicked, the bindings on the form appear
to be permanently lost until I close and re-open the form. I have attached
the relevant portions of the New and Cancel button Click Event routines as
well as a representative portion of the binding initializations. Note that
I only bind the controls at form startup.
Can anyone tell me what I am doing wrong here?
TIA
Ron L
Private Sub BtnNew_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles _btnNew.Click
....
' Create a new row in the data table and change the List Tab's
filter so that the new row is the selected item
Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource, DataTable)
Dim dr As DataRow = dt.NewRow
dr.Item("PPDID") = "NewPPD"
dt.Rows.Add(dr)
CType(cm.List, DataView).RowFilter = "PPDID = 'NewPPD'"
....
End Sub
Private Sub CancelChanges(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles _btnCancel.Click
Dim cm As CurrencyManager
Dim drv, newRow As DataRowView
Dim permLevel As Integer
Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource, DataTable)
dt.RejectChanges()
' reset the previously selected ID.
_listCtlr.SetCurrentRow(_listSelectedID)
drv = CType(cm.List,
DataView).Item(_ppdctlr.ListGrid.CurrentRowIndex)
permLevel = PermissionLevel(drv)
....
End Sub
Private Sub BindUserControls()
Dim dt As DataTable = _ppdctlr.ListGrid.DataSource
_txtPPDID.DataBindings.Add("text", dt, "PPDID")
_txtGlobalID.DataBindings.Add("text", dt, "GlobalID")
_txtDuplicateOf.DataBindings.Add("text", dt, "DuplicateOf")
_txtCPRRequestSubmitted.DataBindings.Add("text", dt,
"CPRRequestedDate")
_cbCPRRequired.DataBindings.Add("Checked", dt, "CPRRequired")
_cbDPRRequired.DataBindings.Add("Checked", dt, "DPRRequired")
_txtTitle.DataBindings.Add("text", dt, "Title")
_txtModDate.DataBindings.Add("text", dt, "ModifiedDate")
_cboType.DataBindings.Add("text", dt, "Type")
_cboProblemArea.DataBindings.Add("text", dt, "ProblemArea")
....
End Sub