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 14 1719
Ron,
I don't see direct the error, however does this work. 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)
That cm (currencymanager is just an address in my opinon without any
reference in it).
Cor
Cor
Thanks for the response. My Bad, the assignment to cm was in the code I cut
for clarity. The following line is in my code just after the
dt.RejectChanges line:
cm =
CType(_ppdctlr.ListGrid.BindingContext(CType(_ppdc tlr.ListGrid.DataSource,
DataTable)), CurrencyManager)
Basically, my problem appears to be that the bindings are lost when the
changes are cancelled.
Ron L
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Ow**************@TK2MSFTNGP14.phx.gbl... Ron,
I don't see direct the error, however does this work.
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)
That cm (currencymanager is just an address in my opinon without any reference in it).
Cor
Hi,
"Ron L" <ro**@bogus.Address.com> wrote in message
news:es**************@TK2MSFTNGP14.phx.gbl... 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?
Did you already set default values for the fields that are bound to
CheckBox, CheckBox can't handle null values (common for new rows) and may
crash the binding, eg.:
dt.Columns( "DPRRequired").DefaultValue = false
dt.Columns( "CPRRequired").DefaultValue = false
Instead you could probely also set the default values after you create the
new row (dt.NewRow), *but* before you add it to the Rows collection.
I know you are not using CurrencyManager.AddNew but the problem with
CheckBox is described here: http://support.microsoft.com/default...b;en-us;326440
hth,
greetings 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
Bart
Thanks for the response. I will give that a try.
Ron L
"Bart Mermuys" <bm*************@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl... Hi,
"Ron L" <ro**@bogus.Address.com> wrote in message news:es**************@TK2MSFTNGP14.phx.gbl... 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?
Did you already set default values for the fields that are bound to CheckBox, CheckBox can't handle null values (common for new rows) and may crash the binding, eg.:
dt.Columns( "DPRRequired").DefaultValue = false dt.Columns( "CPRRequired").DefaultValue = false
Instead you could probely also set the default values after you create the new row (dt.NewRow), *but* before you add it to the Rows collection.
I know you are not using CurrencyManager.AddNew but the problem with CheckBox is described here: http://support.microsoft.com/default...b;en-us;326440
hth, greetings
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
Ron,
May I try to make it for me more clearer.
You add a datarow.
That is in the table the row
dt.rows(count-1)
I would in this remove or delete that datarow again when it is canceled,
what is in this action the same because it is an added row.
Cor
The same is that delete or remove in this case. A little bit unclear when I
have read it back.
Cor
I have tried using both the .RejectChanges method and row.Delete method, and
both have the same effect - my form's fields are empty and won't bind when
another row is selected in the list.
Ron L
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eO*************@TK2MSFTNGP12.phx.gbl... The same is that delete or remove in this case. A little bit unclear when I have read it back.
Bart
Thanks for the thought, but that was apparently not the problem. I put in
the DefaultValues on each of those columns and still have the same results.
Ron L
"Bart Mermuys" <bm*************@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl... Hi,
"Ron L" <ro**@bogus.Address.com> wrote in message news:es**************@TK2MSFTNGP14.phx.gbl... 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?
Did you already set default values for the fields that are bound to CheckBox, CheckBox can't handle null values (common for new rows) and may crash the binding, eg.:
dt.Columns( "DPRRequired").DefaultValue = false dt.Columns( "CPRRequired").DefaultValue = false
Instead you could probely also set the default values after you create the new row (dt.NewRow), *but* before you add it to the Rows collection.
I know you are not using CurrencyManager.AddNew but the problem with CheckBox is described here: http://support.microsoft.com/default...b;en-us;326440
hth, greetings
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
Hi Ron,
What exactly do you mean by bindings are lost?
You can't create new rows?
Do you realize that calling dt.RejectChanges will remove all rows that
aren't yet stored in database (DataRowState.Added) and cancel all other
changes?
Is this the answer?
--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Ron L" <ro**@bogus.Address.com> wrote in message
news:es**************@TK2MSFTNGP14.phx.gbl... 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
Miha
Thanks for the response. Yes, I am aware that this will remove all rows
that aren't stored yet, that is what I am trying to do.
What is happening is that I create a new row which is made current in the
form. If I cancel the form (either deleting that row explicitly or doing a
RejectChanges), the previously selected record should now be displayed in
the form, but the form stays blank. If I go back to my form and select
another row my form remains blank until I reinitialize it.
Ron L
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:eB****************@TK2MSFTNGP10.phx.gbl... Hi Ron,
What exactly do you mean by bindings are lost? You can't create new rows?
Do you realize that calling dt.RejectChanges will remove all rows that aren't yet stored in database (DataRowState.Added) and cancel all other changes? Is this the answer?
-- Miha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Ron L" <ro**@bogus.Address.com> wrote in message news:es**************@TK2MSFTNGP14.phx.gbl... 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
Hi,
"Ron L" <ro**@bogus.Address.com> wrote in message
news:OZ****************@TK2MSFTNGP14.phx.gbl... Bart
Thanks for the thought, but that was apparently not the problem. I put in the DefaultValues on each of those columns and still have the same results.
Even though it doesn't help with your problem you still need to do this,
because the CheckBox will cause problems without a default value.
Other reasons that may cause independent navigating:
- DataSource of DataGrid and the other Controls are no longer the same.
They need to be exactly the same not just producing the same data.
- You have set a new BindingContext to either the DataGrid or to the
UserControl the DataGrid is on.
- You called CurrencyManager.SuspendBinding.
Check whether your app hangs for a small time the first time you add or
cancel the new record, which would indicate some Exception being thrown.
Another thing you can do is check if the CurrencyManager _after_ the problem
is still the same for the DataGrid and one of the TextBoxs, eg.:
Dim tbCM As BindingManagerBase = _
_txtPPDID.DataBindings("Text").BindingManagerBase
Dim dgCM As BindingManagerBase = _
_ppdctlr.ListGrid.BindingContext( _
_ppdctlr.ListGrid.DataSource, _
_ppdctlr.ListGrid.DataMember )
' Should return True
Console.WriteLine( Equals(tbCM, dgCM) )
' Should return True
Console.WriteLine( _
_txtPPDID.DataBindings("Text").IsBinding )
HTH,
Greetings Ron L
"Bart Mermuys" <bm*************@hotmail.com> wrote in message news:%2***************@TK2MSFTNGP15.phx.gbl... Hi,
"Ron L" <ro**@bogus.Address.com> wrote in message news:es**************@TK2MSFTNGP14.phx.gbl... 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?
Did you already set default values for the fields that are bound to CheckBox, CheckBox can't handle null values (common for new rows) and may crash the binding, eg.:
dt.Columns( "DPRRequired").DefaultValue = false dt.Columns( "CPRRequired").DefaultValue = false
Instead you could probely also set the default values after you create the new row (dt.NewRow), *but* before you add it to the Rows collection.
I know you are not using CurrencyManager.AddNew but the problem with CheckBox is described here: http://support.microsoft.com/default...b;en-us;326440
hth, greetings
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
Bart
Thanks, I inserted that code and both show true. I have noticed that if I
move my RejectChanges to follow the code where I choose the previously
selected item, I now have the text fields being filled in, but now my
selection on the Grid doesn't always update the CurrentRowIndex. Whether or
not it changes CurrentRowIndex seems to have to do with one of my fields in
the Grid - one that determines whether the panel others are on is displayed
or hidden I guess I'll have to keep digging there.
Ron L
"Bart Mermuys" <bm*************@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl... Hi,
"Ron L" <ro**@bogus.Address.com> wrote in message news:OZ****************@TK2MSFTNGP14.phx.gbl... Bart
Thanks for the thought, but that was apparently not the problem. I put in the DefaultValues on each of those columns and still have the same results.
Even though it doesn't help with your problem you still need to do this, because the CheckBox will cause problems without a default value.
Other reasons that may cause independent navigating: - DataSource of DataGrid and the other Controls are no longer the same. They need to be exactly the same not just producing the same data. - You have set a new BindingContext to either the DataGrid or to the UserControl the DataGrid is on. - You called CurrencyManager.SuspendBinding.
Check whether your app hangs for a small time the first time you add or cancel the new record, which would indicate some Exception being thrown.
Another thing you can do is check if the CurrencyManager _after_ the problem is still the same for the DataGrid and one of the TextBoxs, eg.:
Dim tbCM As BindingManagerBase = _ _txtPPDID.DataBindings("Text").BindingManagerBase
Dim dgCM As BindingManagerBase = _ _ppdctlr.ListGrid.BindingContext( _ _ppdctlr.ListGrid.DataSource, _ _ppdctlr.ListGrid.DataMember )
' Should return True Console.WriteLine( Equals(tbCM, dgCM) )
' Should return True Console.WriteLine( _ _txtPPDID.DataBindings("Text").IsBinding )
HTH, Greetings
Ron L
"Bart Mermuys" <bm*************@hotmail.com> wrote in message news:%2***************@TK2MSFTNGP15.phx.gbl... Hi,
"Ron L" <ro**@bogus.Address.com> wrote in message news:es**************@TK2MSFTNGP14.phx.gbl... 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?
Did you already set default values for the fields that are bound to CheckBox, CheckBox can't handle null values (common for new rows) and may crash the binding, eg.:
dt.Columns( "DPRRequired").DefaultValue = false dt.Columns( "CPRRequired").DefaultValue = false
Instead you could probely also set the default values after you create the new row (dt.NewRow), *but* before you add it to the Rows collection.
I know you are not using CurrencyManager.AddNew but the problem with CheckBox is described here: http://support.microsoft.com/default...b;en-us;326440
hth, greetings 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
Some parts of your code are missing, for example, how do you get
CurrencyManager.
If you create a sample simple as possible that reporduces the problem (you
can send it to me if you wish) it will be easier to understand what exactly
you are doing.
--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Ron L" <ro**@bogus.Address.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... Miha
Thanks for the response. Yes, I am aware that this will remove all rows that aren't stored yet, that is what I am trying to do.
What is happening is that I create a new row which is made current in the form. If I cancel the form (either deleting that row explicitly or doing a RejectChanges), the previously selected record should now be displayed in the form, but the form stays blank. If I go back to my form and select another row my form remains blank until I reinitialize it.
Ron L
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:eB****************@TK2MSFTNGP10.phx.gbl... Hi Ron,
What exactly do you mean by bindings are lost? You can't create new rows?
Do you realize that calling dt.RejectChanges will remove all rows that aren't yet stored in database (DataRowState.Added) and cancel all other changes? Is this the answer?
-- Miha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Ron L" <ro**@bogus.Address.com> wrote in message news:es**************@TK2MSFTNGP14.phx.gbl... 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
Miha
After looking more into the probem, it appears that there is some
interrelationship with the data. I am not sure quite what the problem is
yet but it appears only with certain rows of my data. We are still trying
to figure it out, but it appears to be related to a pair of combo boxes who
may or may not have a value set, depending on other data selections in the
record.
Ron L
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:uw**************@TK2MSFTNGP09.phx.gbl... Some parts of your code are missing, for example, how do you get CurrencyManager. If you create a sample simple as possible that reporduces the problem (you can send it to me if you wish) it will be easier to understand what exactly you are doing.
-- Miha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Ron L" <ro**@bogus.Address.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl... Miha
Thanks for the response. Yes, I am aware that this will remove all rows that aren't stored yet, that is what I am trying to do.
What is happening is that I create a new row which is made current in the form. If I cancel the form (either deleting that row explicitly or doing a RejectChanges), the previously selected record should now be displayed in the form, but the form stays blank. If I go back to my form and select another row my form remains blank until I reinitialize it.
Ron L
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:eB****************@TK2MSFTNGP10.phx.gbl... Hi Ron,
What exactly do you mean by bindings are lost? You can't create new rows?
Do you realize that calling dt.RejectChanges will remove all rows that aren't yet stored in database (DataRowState.Added) and cancel all other changes? Is this the answer?
-- Miha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Ron L" <ro**@bogus.Address.com> wrote in message news:es**************@TK2MSFTNGP14.phx.gbl... 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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Phil Thompson |
last post by:
Riverbank Computing is pleased to announce the release of PyQt v3.14 available
from http://www.riverbankcomputing.co.uk/.
Changes since the last release include support for QScintilla v1.5.
...
|
by: Arthur Chereau |
last post by:
Hi,
I'm trying to setup viewcvs to work with subversion 1.2.0 on Linux with
Python 2.4.1. The last viewcvs (from CVS) needs subversion python
bindings. I installed swig and built subversion from...
|
by: MajorTom |
last post by:
Hello
I need help. I have a datagrid that have a dataview as datasource.
in the keyup event of one textbox I use dataview.rowfilter = some.text;
when the condition of my rowfilter return...
|
by: Chuck Bowling |
last post by:
I have a typed collection bound to some form components. When information in
the dataset changes I want to mark it as dirty so that I can save it when
the form closes. The...
|
by: Marc Gravell |
last post by:
In the following example, the Bindings don't update the UI if the property
change is triggered from the non-UI thread - see the async button - from the
listbox contents (and observation) the change...
|
by: AlonR |
last post by:
Hi,
We're experiencing random user sessions losses on our web applications,
and are researching for any useful information which may shed light on
this problem.
Environment:
In our...
|
by: Kirill Simonov |
last post by:
Hi,
I've written a pure Python module, which could optionally use an
external C library. The external library is not required to be on the
user computer however, so I'd like not to build the...
|
by: Matteo Bertini |
last post by:
#### PyQt3Support - Python bindings for Qt3Support ####
http://www.develer.com/oss/PyQt3Support
#### What is this?
PyQt3Support is an extension to PyQt4 that adds bindings to Qt's...
|
by: Jason Yamada-Hanff |
last post by:
Hi all,
I'm working on a project that would benefit very much from Python
Freetype2 bindings (the Fonty Python project). I don't want to
duplicate efforts and wrap the library again if we don't...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |