Data Error event : e.cancel operation.

N

NetNewbie

Hi, I have the following code in the Dataerror event of all the grids in my
application.

If (e.Context = DataGridViewDataErrorContexts.Commit) Then
MessageBox.Show("Error Saving Data")
End If

MessageBox.Show(e.Exception.Message, "Exhibit Dates",
MessageBoxButtons.OK, MessageBoxIcon.Error)
e.Cancel = True ' Keeps the focus on the same row
e.ThrowException = False

With this code, if I enter a row and then don't fill in all the values (or
have somthing that violates a condition), then I cannot click on the
bindingnavigator delete button to clear the row.

I wanted to use the e.cancel to keep the focus on the row in case user would
like to correct/edit the record. But if the user chooses to cancel the edit
operation or not save the incorrect row (and choose to remove it) then the
code doesn't allow one to remove the row .

Any suggestions on how to better handle this?

Thank you,
 
C

Cor Ligthert[MVP]

Net Newbie,

As you use DataControls in Net, then work with the datasource in those and
see the Controls only as something that shows what is in the datasource.

That will make you much hapier, it are not a kind of FlexGrids with
recordsets.

Cor
 
N

NetNewbie

I'm sorry Cor Lightert, I don't quite follow what you are saying. You want me
to work with the datasource? Can you please elaborate? From what I've read, I
have to handle the dataerror event to display proper messages, I would also
prefer for the row not to dissapear once the error message is displayed and
the ability to delete oor edit the row
 

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

Top