473,769 Members | 5,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12939
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**********@h otmail.com> wrote in message
news:eG******** ******@TK2MSFTN GP05.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.Inn erException Is
System.FormatEx ception 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**********@h otmail.com> wrote in message
news:eG******** ******@TK2MSFTN GP05.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
3050
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 an int. How can I reference this node?
1
8757
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' type='text/javascript'></script> <script language='javascript' type='text/javascript'>
0
25859
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 from a hyperlink column) into a session. the code is as following: Private Sub ibtAddtoCart_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtAddtoCart.Click idStr = Session("ids") pid =...
1
4016
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 creating many public properties on the form to do the same thing. At first I tried returning a DataViewRow. This worked fine until I reached the phone field on the parent table and the code Child form public DataRowView SelectedAddres ge ...
3
11748
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/ Exception: Type= System.FormatException Message: Input string was not in a correct format. StackTrace: at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
1
4925
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 string was not in a correct format."} If I specify base 10 this works on all machines Convert.ToInt32(“0”,10); So I have 3 related questions.
3
2050
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 (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?
0
3130
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 id="grdShoppingCart" OnItemDataBound="ItemDB"
13
10395
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 being convert to an Int16 (using Convert.ToInt16). How can that be? There are other text boxes that are used in the identical fashion and they don't generate the exception. All there are many other machines running my application that don't...
9
8188
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" exception because the decimal field in one of the incoming fields is written in exponential form. I've looked at generating the XML with a fully written decimal value (as opposed to using exponential notation) but that's an issue because right now the...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.