Trouble getting a row add to cancel in DataGridView


B. Chernick

Someone refresh my memory. I have a datagridview bound to a binding source.
(VB/Dot Net 2.0). Adds are permitted in the DataGridView.

Assuming that I'm in 'Add Mode' (I'm in a cell of the bottom row) I wish to
test the contents of a cell in the new row on exit (from that cell, NOT from
the new row). If the test fails, I want the Add to be cancelled. I want
everything in the add row to vanish. I want the grid to go back to the
current last existing row. I seem to be having some trouble getting this to

What's the preferred method?



You can make use of DataSet class in the name space "System.Data" .

What i use normally is

1-> call DataSet.GetChanges() which returns Added/Modified rows collection
2-> Validate each row and set DataRow.SetColumnError() if validation fails
for a colums
3-> call DataRow.AcceptChanges() if validation is success.

you can also use DataSet.RejectChanges() to discard any changes made in the
data set.


DataSet.GetChanges() returns Modified/Added rows , after validating the rows
you can call DataRow.AcceptChanges/RejectChanges.

B. Chernick

Interesting point. Unfortunately this ad-hoc project's specs have changed so
many times since I posted this that I have an entirely different set of
problems now . :)

But thanks anyway. This is a good review of the gridview.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question