5

I have a DataGridView with its datasource set to a generic list of custom objects. As the user changes values (in this case checks/unchecks a check box) the underlying boolean field in the object changes.

Should I be creating a "copy" of the List for binding, then updating manually if the user commits, (if so how do you create this copy), or is there a simple way to rollback changes made to the datasource.

(I'm using C#)

Stuart Helwig
  • 9,318
  • 8
  • 51
  • 67

1 Answers1

1

Technically unless you're telling it to, it's not updating your actual datasource, just the list you've bound to the grid. You're still free to dispose of this list and re-query your source to refresh it back to it's previous state.

You might just add a commit option for the users to commit all the changes they've made back to the actual data source.

It would be a lot easier and probably a whole lot less intensive to handle it like that. Then you can simply have a "cancel changes" or some such option that will refresh and rebind the list from it's source again, without performing an update.

Hope this helps!

Cheers!

thismat
  • 2,096
  • 17
  • 24
  • I was passing my list to the form that was binding. (It is built from an XML file). I think you've highlighted my mistake. I need to create a new List<> collection for binding, (not use the "live" one, and commit changes only when the user wants to (clicks OK) Thanks. – Stuart Helwig Oct 28 '08 at 22:39
  • To copy the object you are sending to edit form. Implement a copy constructor to create a copy of the original object. Then assign or discard as per use case. http://stackoverflow.com/a/6569799/384554 – PUG Mar 19 '15 at 03:50