There are a couple possible solutions. First though, it is important to understand what data binding is doing.
When the user selects an item in the datagrid, that item's edit level is elevated because the item has currency. When the user moves off that row CancelEdit() or EndEdit() is called, which decrements the edit level - of course now some other row will have currency.
For a new item that has no changes, binding knows to call CancelEdit() - well, these days it actually uses the ICancelAddNew interface on the collection - to remove the new-but-unchanged item.
Any change to the new item though, means EndEdit() is called, because the item has been changed and it is assumed the user wants to keep it. If they didn't want to keep it they'd have pressed ESC (which would have reset the row to be unchanged) first right? :)
If you have a dialog window and that window uses data binding, THAT WINDOW has its own currency. Actually it isn't the window, it is the bindingsource. But the point is that the window will have currency.
It is almost certainly the case that data binding sees the dialog having currency as a reason to do an EndEdit() on the row. In other words, data binding no longer thinks the item is "brand new" and so it won't auto-remove it anymore.
I haven't tried this, but I bet you'd have the same problem with a DataTable too - because I think this is a currency issue at the data binding level.
In other words, you'll probably need to have code-behind the main form that understands that
and therefore knows to explicitly remove the new item from the collection via the bindingsource.
Copyright (c) Marimer LLC