Hi all,
I'm working on a framework understanding in C#. I have a form with simple add/edit, save/cancel (and Exit) buttons on a form. The form has a grid, and a datatable bound to it (data table is a field on the form for scope purposes to remain for duration of the form).
Also on the form are 3 simple textbox controls bound to respective columns in the DataTable. When I scroll the grid, the textbox details automatically refresh... perfect.
I have add / cancel coordination working fine, but failing on edit / cancel. Failing with respect to the following.
I start the form, grid displays 3 rows (column 1 is a simple "Description"). First row has a value "Test" (so shows the corresponding bound individual textbox control on the form). I click edit button and can now change the individual textbox (not the datagrid) and change it to "Test changed value".
So, now, I go to click the "Cancel" button and hope for the following... The grid does NOT get updated with the new value, and the individual textbox control goes back to its original "Test" value.
In the Cancel button, I issue a MyDataTable.RejectChanges(), and the grid properly retains the original "Test" value, but the textbox control keeps the "Test changed value" content. When I have this same "RejectChanges()" call during the add/cancel combination, it all works perfectly.
To simulate a similar during the add/cancel, I am explicitly forcing the grid to the last valid row in the datatable which in-turn updates the textboxes... Apparently, something in the calling / reloading process of the MyDataGridView.CurrentRow getting triggered does something I can't see. Since its an EDIT, I'm not removing a row from the table (temporary from the "Add"), and then rejecting (which removes), and forces a row change via MyDataGridView.CurrentCell = [0, LastDataRowInDataTable]
Any thoughts would be great.