简体   繁体   中英

c# bound Datagridview

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM