|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to prevent "Input string was not in a correct format" in DataGridViewHi,
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 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/library/system.windows.forms.datagridview.cellvalidating(VS.80).aspx http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.dataerror(VS.80).aspx Ken --------------- Show quote "Pieter Coucke" <pietercou***@hotmail.com> wrote in message news:eGiRQP5YGHA.4424@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 > > > 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... On Wed, 19 Apr 2006 13:20:03 +0200, "Pieter Coucke" <pietercou***@hotmail.com> Have you tried what Ken suggested??wrote: >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... > Good luck with your project, Otis Mukinfus http://www.arltex.com http://www.tomchilders.com Yes I tried the CellValidating-event, and could check it with a
Typeconverter, but wasn't able to put the old value back when I needed... You might want to put a validator to validate the entry so the form is not
posted to the server with invalid data Show quote "Pieter Coucke" <pietercou***@hotmail.com> wrote in message news:eGiRQP5YGHA.4424@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 > > > |
|||||||||||||||||||||||