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 Dirk Haest
Dirk Haest
Flag of Belgium image

Did you check this event:
DataGridView..::.RowLeave Event

Occurs when a row loses input focus and is no longer the current row.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowleave.aspx
perhaps better:
DataGridView..::.RowValidating Event

Occurs when a row is validating.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowvalidating.aspx
Avatar of ekenman
ekenman

ASKER

The DataError is thrown before both the other events and erases the row....
Hi,

If you are using DropDownList in Datagridview then you will be using EditItemTemplate isn't? They you can use RequiredFieldValidator for the DropDownList and validate the input.
Avatar of ekenman

ASKER

That sounds perfect Giftson. I'm not sure where I'll find EditItemTemplate and RequiredFieldFalidator.
ASKER CERTIFIED SOLUTION
Avatar of GiftsonDJohn
GiftsonDJohn
Flag of India 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

Oh... This is a Windows Client and not ASP. I presume you are talking about switching to code view from html?
Okay. Then it is wrongly posted in Asp.Net Zone.
Avatar of ekenman

ASKER

Ooops... Sorry about that one. I'll try to correct this...
Avatar of ekenman

ASKER

I'll assign you points anyway since you answered it and start a new question in the right forum.
Avatar of ekenman

ASKER

Thank's!