[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error Handling in DatagridView

Posted on 2009-04-24
11
Medium Priority
?
609 Views
Last Modified: 2013-11-08
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
0
Comment
Question by:ekenman
  • 6
  • 3
  • 2
11 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24223484
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
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24223489
perhaps better:
DataGridView..::.RowValidating Event

Occurs when a row is validating.

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

Author Comment

by:ekenman
ID: 24223929
The DataError is thrown before both the other events and erases the row....
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24224109
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.
0
 

Author Comment

by:ekenman
ID: 24224775
That sounds perfect Giftson. I'm not sure where I'll find EditItemTemplate and RequiredFieldFalidator.
0
 
LVL 14

Accepted Solution

by:
GiftsonDJohn earned 1500 total points
ID: 24224826
Switch to code view in Visual Studio. In the GridView definition you will find <columns> tag and you would have defined all columns to be displayed. There you can find the <EditItemTemplate>.
0
 

Author Comment

by:ekenman
ID: 24224949
Oh... This is a Windows Client and not ASP. I presume you are talking about switching to code view from html?
0
 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24225002
Okay. Then it is wrongly posted in Asp.Net Zone.
0
 

Author Comment

by:ekenman
ID: 24225030
Ooops... Sorry about that one. I'll try to correct this...
0
 

Author Comment

by:ekenman
ID: 24225042
I'll assign you points anyway since you answered it and start a new question in the right forum.
0
 

Author Closing Comment

by:ekenman
ID: 31574157
Thank's!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question