Hi,
I am trying to create a numeric textbox in C#.
I got few useful links and used them but when I am using special characters then its crashes.
Please advice.
Thanks
Printable View
Hi,
I am trying to create a numeric textbox in C#.
I got few useful links and used them but when I am using special characters then its crashes.
Please advice.
Thanks
Textbox can only support text/string. You need to cast or convert or .tostring your value so it's appropriate before assigning to a textbox.
Well, "1" is a string, and so is "1.2345". I think that is what the OP means.
However, I don't get how you expect us to psychically debug your code. I would bet that your validation routine is just poor and you are trying to convert a string of an incorrect format to an integer, floating point number, whatever.
I figured he was trying to do something like this: textbox1.text = 40; since he said it was crashing. But yeah you're probably right with what you said about what he was probably trying to do; escpecialy since he did mention special characters.
I meant I thought he was trying to do something like: textbox1.text = IntegerVariable;. Man lately I can't express a thought accurately in writing on the first shot.
I got the point the first time :)
check this article
http://www.mindstick.com/Articles/6e...-a8b756404f09/
select your textbox and then from events double click on Keypress and paste this code
this code will disable all characters on textbox except backspase and delete. if you want to use "," then just paste after != Delete this codeCode:const char Delete = (char)8;
e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete);
Code:&& (e.KeyChar != Convert.ToChar(",")
Thanks John & invador
What about a decimal? Do you need to be able to handle decimal numbers or only integers.
Also invader, backspace is 8, delete is 46. Why don't you just use the Keys enumeration?