views:

87

answers:

1

I have a binded DataGridView that allows adding new rows. The problem is that a new object is automatically inserted in the binding source when the CurrentRow is the last grid row. I want that a new object to be added to the binding source only when the user starts typing in one of the last row cells.

+1  A: 

That's not the way DataGridView works, and having tried before to change the way adding new items works, I have to caution you against trying it.

Your best option is to have your binding source implement the ICancelAddNew interface. If this interface is implemented, then the DataGridView will call CancelNew if the user leaves the row without entering any data into the new item. You can also use a BindingList as your data source, or wrap your data source in a BindingSource; both of these classes implement ICancelAddNew.