By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,406 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.