Accept / Cancel changes in Subsonic 2.2

95 Views Asked by At

I have a .NET 2.0 Winforms app (and Subsonic 2.2), where I have a DataGridView and few controls in a panel, both are bound to a BindingSource whose datasource is a Subsonic ActiveRecord collection. When a user selects a row in grid, the corresponding details are shown in the panel below in appropriate controls (texbox, combo, datetimepicker, etc.)

When a user changes some data, and tries to move to some other row, I want the app to display a warning that data has changed and it needs to be saved. If user selects yes, the data should be persisted.

I face a few issues:

a) In the DGV.RowEnter event handler, I try to find if the current row is dirty (using IsDirty of activerecord). If so, I display a messagebox.

b) When I save and rebind the grid, the datasource of the datagridview cannot be re-bound to a new (saved) collection. The app throws error that 'operation is invalid'.

c) Also, since both the gridview and controls are bound to same collection, whenever I change something in the control, it is reflected in grid, but when user selects 'No' to save data, the changes should be undone. Does subonic has any Accept / Cancel changes like a dataset?

Thanks!

1

There are 1 best solutions below

0
On

I finally figured it out:

a) While I am able to save data without any issues, the app throws error only when I try to "rebind" it. As the grid and controls are already bound to datasource, which contains latest changes, I removed the rebinding code and now it no longer throws any error ("Operation is invalid"

b) Undoing changes - this was accomplished by calling BindingSource.CancelEdit() when user does not want to save changes.