[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB.Net, Catch "DataGridView Default Error Dialog" Exception

Posted on 2012-04-02
8
Medium Priority
?
1,756 Views
Last Modified: 2012-04-03
Hi Experts,

I am  using VB.Net and datagridview.

In my gridview I have got three columns. And in the second and third column I have set the format to currency.

The main problem is, if there was any error raised, an DataGridView Default Error Dialog box is shown. But to avoid that error dialog box , data error Event is used.

But what I need is that I need to catch that error in a try catch block, but I don't know where to put the try catch block to catch the error.

The error occurs when I leave a cell blank and move to another cell
0
Comment
Question by:baabaa_nl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37798227
set a defaut value for the column where the cell belongs.
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 1000 total points
ID: 37798280
or you can handle the cellvalidating event, aka
If String.IsNullOrEmpty(e.FormattedValue) Then
         e.Cancel = True
     Else
         e.Cancel = False
End If

Open in new window

0
 

Author Comment

by:baabaa_nl
ID: 37798290
i tried that code, and it was eliminating the check box. but wat i need is to catch that error my self using a try catch block, but i dont know where to put the try catch block
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 17

Expert Comment

by:nepaluz
ID: 37798318
put a check for the respective column before applying the code!
Else you will need to put your try-catch in the CellEndEdit event
0
 

Author Comment

by:baabaa_nl
ID: 37798346
I didn't  understand the first part of your comment about
>>put a check for the respective column before applying the code!


Also i was using DataError Event, and not the CellEndEdit Event.

Also, i tried using a try catch block for the CellEndEdit event, but it didnt make use of it, it was as if the try catch block was ignored.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 1000 total points
ID: 37801944
You can not use try catch block here as its not an exception. It is a Data Error!
0
 

Author Comment

by:baabaa_nl
ID: 37802150
Hi CodeCruiser,

I really don't know from which part of the code the exception is raised, but the only way to stop it is by using the dataerror event.

But the main problem is, the exception is due to many reason, one could be due to a null value and other due to incorrect double format and many more. but in order for me to specifically to catch the exception, I require the try catch block, but I don't know where to put it.

so is there anyway that I could find the cause of the reason of the exception on the dataerror event.

This may sound really false, but I feel that the error is raised from the designer code? Is that possible.

Thanks in advance.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 1000 total points
ID: 37802222
>the exception is due to many reason, one could be due to a null value and other due to incorrect double format and many more. but in order for me to specifically to catch the exception, I require the try catch block, but I don't know where to put it

Again. That is not exception. That is data error. It is raised by DataGridView when it tries to commit the value to underlying data layer (datatable). It then uses the DataError to notify you of the problem. Try using the e parameter in DataError to see if you can get any info.
0

Featured Post

Industry Leaders: 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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

649 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