Is it possible to update data in the datagrid without having to bind it to a particular object and still enjoy the benifits of a “two way” data binding? In this case the type of object to be binded is decided at runtime based on user input.
Some more clarity:
Actually I am using a multi threaded application and I need to update data in UI from another thread. For this purpose I share a reference for an Observable Collection object and bind(through ItemsSource) the same to the data grid. Now, whenever the thread updates the data, it calls a specific function in the UI thread asking it to refresh the datagrid. The problem arises when I try to modify some value in the grid so that it is sent back to the thread that is running in parallel. It throws an exception “‘DeferRefresh’ is not allowed during an AddNew or EditItem transaction.”
With a DataGridView you can change the datasource at runtime and still enjoy two-way binding… Just set the DataSource to null first.
If for some reason you can’t do that, you might consider object composition: i.e. binding your grid to an intermediate object which simply holds a variable for the actual object you’re ‘binding’ at runtime, and create wrappers for the implementation (IList, IListSource, IBindingList or IBindingListView).
Unless I’ve missed something?