I normally manually populate my forms fields and handle everything from there owing to years ago giving up owing to all the practical problems with bound Winform controls in all but the simplest scenarios. Thought I'd give it another shot.
I have a grid populated with a datatable (not connected to a dataset) and fields bound to the same datatable. When the user selects a grid record, the below fields are populated with the record and edited. I want an Undo button that they can change edits to the current record but everything I try does not clear the textbox, and even the underlying table unless it is already dirty. Here is how I am handling:
binding a textbox (_dtUsers is a datatable):
Here is how I am trying to undo (note "CurrentRow" is a property I capture on ColumnChangeing or RowChanged events)
The major problem: before changing records, the datatable doesn't know the row has been changed and RejectChanges does nothingto the current row. After the table is dirty, it will clear the current row but the text box will not reflect the change unless I go to another row and return.
So here's what I want:, if possible:
On a textbox (or other bound control) change--which does fire the Column and Row changed evenets of thte bound table-- I want to set the table to "Dirty", that is that it knows the row has been edited before moving on to another record. Then when I RejectChanges(), the record will revert to previous value and the textbox will also reflect it..
Thanks.
I have a grid populated with a datatable (not connected to a dataset) and fields bound to the same datatable. When the user selects a grid record, the below fields are populated with the record and edited. I want an Undo button that they can change edits to the current record but everything I try does not clear the textbox, and even the underlying table unless it is already dirty. Here is how I am handling:
binding a textbox (_dtUsers is a datatable):
C#:
txtFirstName.DataBindings.Add(new Binding("Text", _dtUsers, "UFNm"));
Here is how I am trying to undo (note "CurrentRow" is a property I capture on ColumnChangeing or RowChanged events)
C#:
{
try
{
txtUserID.Focus(); //to force a field move
if (!CurrentRow.IsNull())
{
CurrentRow.RejectChanges();
}
}
catch (Exception ex)
{
_mainform.HandleException(ex);
}
}
The major problem: before changing records, the datatable doesn't know the row has been changed and RejectChanges does nothingto the current row. After the table is dirty, it will clear the current row but the text box will not reflect the change unless I go to another row and return.
So here's what I want:, if possible:
On a textbox (or other bound control) change--which does fire the Column and Row changed evenets of thte bound table-- I want to set the table to "Dirty", that is that it knows the row has been edited before moving on to another record. Then when I RejectChanges(), the record will revert to previous value and the textbox will also reflect it..
Thanks.
Last edited by a moderator: