On Aug 29, 1:54*pm, "jehugalea...@gmail.com" <jehugalea...@gmail.com>
wrote:
Hello:
I am binding a DataGridView with a BindingList<T>, where T is a custom
business object that implements INotifyPropertyChanged.
When you bind a DataGridView to a DataTable, it has this cool little
feature - it will not call DataTable.Rows.Add until after you leave
the DataGridView row. This is cool because it lets your user edit the
record as much as needed to get it into a valid state before actually
adding it to the DataTable.
I obviously loose this somewhere when I switch to my custom business
object. Is this something I have to implement at the business object
level or at the BindingList level? And either way, can someone give me
an example implementation?
Thanks,
Travis
I was able to find *a* solution by looking at MSDN. I looked at
System.ComponentModel.ICancelAddNew. I just had to override
BindingList<T>'s CancelNew, InsertItem, and EndNew methods.
I needed to do this because as soon as an item was added to a
DataGridView, it needed to be immediately added to a DataTable as a
row. But, instead of just binding directly to a DataTable, I create a
mapper to help separate my Data layer from my Business layer. I have a
BindingList class that will automatically take changes and map those
to DataTable using the mapper (such as adding, removing and updating
the business objects).
However, it was hard to use my BindingList because I couldn't get the
AddNew semantics to match DataView's. Now I think I have achieved that
goal.