Link to home
Start Free TrialLog in
Avatar of ekenman
ekenman

asked on

Error Handling in DatagridView

I have a Datagridview that is bound to a dataset.

The datagridview contains four columns:

1. Dropdownlist of Companies
2. Dropdownlist of Accounts
3. Textbox: Debit Amount
4. Textbox: Credit Amount

The dataset does not allow null values in the 1,2 column.

In the datasets Partial Class I've added Error Handling for this and they show up in the Datagridview as they should.

However, the user is allowed to leave the row even though there are errors on the rows columns. When this happens, the DataGridViews DataError event is thrown and the users row is deleted. How to avoid this? Is there a post row change event that can check for errors?

Best Regards

Tomas
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

What error message do you have ? You can handle the error on DataError event and don't show it if isn't really an error.
Avatar of ekenman
ekenman

ASKER

I was off yesterday, so sorry for the late answer.
CodeCruiser, I tried the RowValidating event, but it is thrown after the dataerror, so the row is allready gone.
The error message that I'm having trouble with is if the user omitted to select a company (column 1) , or account (column 2) from the dropdownlists. So what I really want is to force the user to fill these out before continuing. But... the row is deleted.
 
Avatar of ekenman

ASKER

(And I've put the validation code in the dataset. )
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ekenman

ASKER

I get Cancel is not a member of System.Windows.Forms.DataGridViewCellEventArgs
Avatar of ekenman

ASKER

But there is one in the dataerror event. OK, That works perfectly. THANK YOU!
Can you show what you have and also what version of VB do you have ?
Ok, glad I could help!
Avatar of ekenman

ASKER

Sure did! Thanks!
I think i provided the original direction of using the RowValidating event!!!!
Avatar of ekenman

ASKER

CodeCruiser, the solution was not to use the RowValidating event since it does not work with error event handling in the dataset. The code that jpaulino provided should be in the DataError event since the DataGridViewCellEventArgs does not have a cancel method as the DataGridViewDataErrorEventArgs does. So it was a typing error by jpaulino. However, that was shat solved my problem.
I'm still gratefull for your effort in helping me.
/Tomas