Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.Net: DataGridView Default Error Dialog

Posted on 2012-04-01
4
Medium Priority
?
2,767 Views
Last Modified: 2012-04-02
Hi,

I am using vb.net.

I have a datagridview with four columns.

The last two columns which are named Debit and Credit. Under the designer, I set the format to currency with two decimal places.

Grid View Pic
Now when I enter any whole or double values and after I leave the cell, immediately the number gets a currency symbol next to it.(Which is what I wanted and is working properly)

But when I delete the number and try to move to another cell, I get the "DatagridView Default Error Dialog" and within that error message dialog and at the end of the dialog box I get the following statement saying that to use the "DataError Event" to handle the problem.

Dialog Error Message Box
After I use that event , I was able to avoid the error. and within that event I tried to replace the cell value to 0 or 0.0 if the user deleted the value and leave the cell.

But by doing that it did not work. I didn't get any errors, but the value 0.0 was not printed on the cell. I have given a detailed information about that event below:

First I got the current cell's column and row index to get the value from the cell. the value that showed was the value that was deleted from the cell.

So after that I wanted to replace that null or white space or empty cell with a value of 0.0 at the data error event.

But the value was not printed in the cell, and after that I checked the value on a messagebox, and it showed that the value was 0. but even then the cell was empty. Also when I tried to move to another cell,  the data error event was getting fired again and again.

Could you please help me to solve this problem.

Thanks in advance.
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
  • 2
4 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37792893
Rather than try to set the value of the cell in the DataError event of the datagridview, set a default value for cells in that column, that way, all new rows will have a value of 0.0 in that column.
0
 

Author Comment

by:baabaa_nl
ID: 37792898
Could you please give me the code and if possible the designer method to do that?

Also if i empty a cells value, how can i set that cell a value of 0 if the cell is left blank.

Thanks in advance
0
 
LVL 17

Assisted Solution

by:nepaluz
nepaluz earned 1000 total points
ID: 37792909
In the designer, set the NullValue via the DefaultCellStyle, aka
desgnOr you can set in code
Me.DataGridView1.Columns(0).DefaultCellStyle = New DataGridViewCellStyle With {.NullValue = 0.0}

Open in new window

Assuming you are setting for the first column
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1000 total points
ID: 37795461
Use e.ColumnIndex and e.RowIndex to access the cell.

At the end of event handle for DataError event, set e.cancel = true.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewdataerroreventargs.aspx

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
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…
Suggested Courses

730 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