tags:

views:

345

answers:

1

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#)

+1  A: 

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
I was passing my list<custom_object> 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