views:

54

answers:

1

I have a datagridview and it is bound to a stored procedure which returns a number of result columns.

There is also a binding navigator with "Add New" button included.

If I click "Add New" button, it creates a new row in datagridview automatically, and If I leave that new row by clicking a different row. datagridview invokes "commit" or something.

so the question is How do I make datagridview not to commit adding a new row when I leave the cell?

A: 

Handle the DataGridView.RowValidating event.

From MSDN:

Use this event to perform validation on all the values of a row. If the row does not pass validation, set the CancelEventArgs.Cancel property to true. Canceling this event prevents the RowValidated, Control.Validating, and Control.Validated events from occurring, and also prevents the user from leaving the invalid row and prevents the row from being saved to an external data source in data bound mode.

Taking an eye out the BindingSource class might also give you ideas, since you say you're using a BindingNavigator along with the DataGridView.

Deeper details could be provided with further details.

Will Marcouiller