|
-
September 21st, 2010, 11:37 AM
#1
Numeric Textbox!
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
-
September 21st, 2010, 11:41 AM
#2
Re: Numeric Textbox!
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.
-
September 21st, 2010, 05:52 PM
#3
Re: Numeric Textbox!
 Originally Posted by viperbyte
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.
-
September 21st, 2010, 06:01 PM
#4
Re: Numeric Textbox!
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.
-
September 21st, 2010, 06:19 PM
#5
Re: Numeric Textbox!
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.
-
September 21st, 2010, 06:20 PM
#6
Re: Numeric Textbox!
I got the point the first time
-
September 22nd, 2010, 06:08 AM
#7
-
September 22nd, 2010, 10:33 PM
#8
Re: Numeric Textbox!
select your textbox and then from events double click on Keypress and paste this code
Code:
const char Delete = (char)8;
e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete);
this code will disable all characters on textbox except backspase and delete. if you want to use "," then just paste after != Delete this code
Code:
&& (e.KeyChar != Convert.ToChar(",")
-
September 23rd, 2010, 04:13 AM
#9
Re: Numeric Textbox!
-
September 23rd, 2010, 11:43 AM
#10
Re: Numeric Textbox!
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|