473,395 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to prevent "Input string was not in a correct format" in DataGridView

Hi,

When a user types a non numeric-value in a numeric column in a DataGridView,
and he tries to leave the cell, he gets this "Input string was not in a
correct format."-exception.

Is there a (nice) way to get rid of this exception? And just put a "0" in
the place? Or somehow trigger this single exception (does exceptions have a
unique type-number?) and do some appropriate actions?

Thanks a lot in advance,

Pieter

Apr 19 '06 #1
3 12907
Hi,

I would use the cellvalidating event to check the format but
there is a dataerror event for dealing with that messagebox.

http://msdn2.microsoft.com/en-us/lib...ng(VS.80).aspx

http://msdn2.microsoft.com/en-us/lib...or(VS.80).aspx

Ken
---------------
"Pieter Coucke" <pi**********@hotmail.com> wrote in message
news:eG**************@TK2MSFTNGP05.phx.gbl...
Hi,

When a user types a non numeric-value in a numeric column in a
DataGridView, and he tries to leave the cell, he gets this "Input string
was not in a correct format."-exception.

Is there a (nice) way to get rid of this exception? And just put a "0" in
the place? Or somehow trigger this single exception (does exceptions have
a unique type-number?) and do some appropriate actions?

Thanks a lot in advance,

Pieter

Apr 19 '06 #2
Thanks. i'm now using a "If TypeOf e.Exception.InnerException Is
System.FormatException Then" in the DataError. but isn't there a way to
correct the value? Put the old value in the cell? Because now my users are
getting really confused: they go to another tab (and see this tab), but the
error is pointing to the previously used tab...
Apr 19 '06 #3
You might want to put a validator to validate the entry so the form is not
posted to the server with invalid data

"Pieter Coucke" <pi**********@hotmail.com> wrote in message
news:eG**************@TK2MSFTNGP05.phx.gbl...
Hi,

When a user types a non numeric-value in a numeric column in a
DataGridView, and he tries to leave the cell, he gets this "Input string
was not in a correct format."-exception.

Is there a (nice) way to get rid of this exception? And just put a "0" in
the place? Or somehow trigger this single exception (does exceptions have
a unique type-number?) and do some appropriate actions?

Thanks a lot in advance,

Pieter

Apr 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Punisher | last post by:
Ok I'm trying to reference a specific node in a tree. TreeNode nodeParentChannel = treeview1.Nodes; It bugs out with this error: Input string was not in a correct format Obviously 1.2 is not...
1
by: The Crow | last post by:
if the reason for error is simple, excuse me. but i cant find what the reason is. Here is the snippet : string script = String.Format(@"<script src='common.js'...
0
by: phmyhn | last post by:
I have two web pages, one is viewlarger.aspx, another one is shoppingcart.aspx. On the viewlarger.aspx, when clicking "add to cart" image button, the sub appends the id (passed from another page...
1
by: John Chorlton | last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid...
3
by: dan | last post by:
I am using VB.NET 2003 and SQL Server 2000. The program uses ADO.NET . The following instruction: Me.cd_insertDataRecord.ExecuteNonQuery() throws this exception: ">>>ProcessDataRecord/...
1
by: James Pose | last post by:
Convert.Int32 fails for "0" but works fine for all other numbers. This does not work on one machine when "0" it works fine on other machines Convert.ToInt32(“0”); gives exception {"Input...
3
by: Pieter Coucke | last post by:
Hi, When a user types a non numeric-value in a numeric column in a DataGridView, and he tries to leave the cell, he gets this "Input string was not in a correct format."-exception. Is there a...
0
by: bnlockwood | last post by:
G'day all, Thank you in advance for anyone that can help. I have a shopping cart datagrid on my c# asp.net page. This is the code: ------------------------------------- <asp:datagrid...
13
by: Jen | last post by:
One user of my application is experiencing an exception "input string not in correct format". But it makes no sense where it is occurring. It is occurring when a string from a textbox ("172") is...
9
muaddubby
by: muaddubby | last post by:
Hi I'm running into a scenario with a DataSet that has a schema loaded into it, tries to then load data (that matches the schema), and fails with a "Input string was not in a correct format"...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.