cleared textbox reverts to orginal value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I have a text box that is bound to a number field in my dataset (not even a strongly-typed dataset), clearing out that field by selecting the text and pressing delete raises a first-chance exception in mscorlib of Input string was not in a correct format then ignores the update to the field and reverts back to the original text. Is there any way around this? My users have to type in 0 into any field they want to clear, but 0 and "" or null do not necessarily mean the same thing.
 
In your delete handler:

If textbox.text = "0" then textbox.text =""

AKABAK said:
When I have a text box that is bound to a number field in my dataset (not
even a strongly-typed dataset), clearing out that field by selecting the
text and pressing delete raises a first-chance exception in mscorlib of
Input string was not in a correct format then ignores the update to the
field and reverts back to the original text. Is there any way around this?
My users have to type in 0 into any field they want to clear, but 0 and ""
or null do not necessarily mean the same thing.
 
Thanks for your response. A couple of things it brought up, though ...

First of all, what delete handler? Pressing the delete key in a textbox doesn't even kick off the KeyPress event.

Second, even if I could handle the delete key, I would have to add that handler to literally hundreds of text boxes.

And third, it won't really work because I wouldn't know if my users were typing 0 because 0 was the appropriate value for that field or 0 because they wanted to clear it.

Can anyone confirm that this is a bug and give me some sort of control-level workaround?
 
Usually this message indicates that you try to convert something whose text
representation is not valid (here you try to convert an empty string to a
numeric value ?). You'll have probably to check for the empty string so that
you can convert to dbnull...

Patrice

--

AKABAK said:
When I have a text box that is bound to a number field in my dataset (not
even a strongly-typed dataset), clearing out that field by selecting the
text and pressing delete raises a first-chance exception in mscorlib of
Input string was not in a correct format then ignores the update to the
field and reverts back to the original text. Is there any way around this?
My users have to type in 0 into any field they want to clear, but 0 and ""
or null do not necessarily mean the same thing.
 
Back
Top