Hi,
I have a WinGrid bound to a BindingList containing some objects (class DataObject).
The grid has AllowAddNew set to FixedAddRowOnBotton.
When a click on the AddRow, the BindingLists AddingNew handler is creating a new object, that is displayed in the AddRow. If I now click on one of the other rows, the AddRow is cleared and the new object is removed from the BindingList. This is what I expected.
Now I implement IEditableObject on DataObject, and the grids behaviour changes:
When I click away from the AddRow, the new object is NOT removed from BindingList. Instead CancelEdit() is called (and then EndEdit()), and the object is still displayed in AddRow. There is no longer a * in AddRows RowSelector.
What should I do, to make the grid remove the object from the BindingList, when IEditableObject is implemented?
Regards,
Klaus
Visual Studio 2008.NET Framework 2.0WinGrid ver. 8.2.20082.1000
Hi Mike,
If you bind a grid to a BindingList containing business objects, that don't implement IEditableObject, the grid calls CancelNew(...) on the BindingList.
If the business objects implement IEditableObject, the grid calls CancelEdit() on the object, but forgets to call CancelNew(...) on the list.
The problem is of course, that IEditableObject.CancelEdit() can reset the state of the object, but it doesn't know anything about the collection(s) it is put into. To remove the object from the BindingList, the grid has to call BindingList.CancelNew(..) - that's why it's there.
Developer Support doesn't think it's an error. I'm not happy about it, but I won't pursue it.
My work-around is to wrap my business objects (that implements IEditableObject) in an object, that holds a reference to the business object and a reference to the BindingList. This wrapper class is then able to remove an object from the BindingList, when it is cancelled during creation.
Best regards,Klaus
Hi Klaus,
If CancelEdit is called, then the object should be cancelled and thus removed from the list. If that item still shows up in the grid, then this is either a bug in the grid, or your implementation of IEditableObject is not correctly cancelling and removing the item - or perhaps it's not sending the proper notifications when this occurrs.
If you feel that your IEditableObject implementation is correct and that this is a bug in the grid, I recommend that you create a small sample project demonstrating this and Submit an incident to Infragistics Developer Support.