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
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
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.
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.
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.
ASKER
(And I've put the validation code in the dataset. )
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get Cancel is not a member of System.Windows.Forms.DataG ridViewCel lEventArgs
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!
ASKER
Sure did! Thanks!
I think i provided the original direction of using the RowValidating event!!!!
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 DataGridViewDataErrorEvent Args 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
I'm still gratefull for your effort in helping me.
/Tomas
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowvalidating.aspx