textbox check
-
hi, I have a textbox. how can i avoid that a user types strings in it, bud only decimal values? thanx
-
hi, I have a textbox. how can i avoid that a user types strings in it, bud only decimal values? thanx
Djavid j wrote:
I have a textbox. how can i avoid that a user types strings in it, bud only decimal values?
MaskedTextBox could be used, or you could handle the Key events (KeyDown, KeyPress, KeyUp) and look at what was typed there, only allowing characters that pass your criteria through. There may be other ways. Good Luck!
It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?
-
hi, I have a textbox. how can i avoid that a user types strings in it, bud only decimal values? thanx
Or use a NumericUpDown instead.
-
hi, I have a textbox. how can i avoid that a user types strings in it, bud only decimal values? thanx
When you convert the TextBox.Text value to a number make sure you catch InvalidCastExceptions which should indicate if the user input was too small/too big/not a number. Read this post, this should help you: http://iheartdotnet.blogspot.com/2007/09/cast-vs-doubleparse-vs-converttodouble.html[^]
-
hi, I have a textbox. how can i avoid that a user types strings in it, bud only decimal values? thanx
I think it is pretty easy to prevent user from entering any text value, we may use following lines of code in KeyPress event of Text box– private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (Char.IsLetter (e.KeyChar)) e.Handled = true; } I hope this helps:). -Dave.
Dave Traister, ComponentOne LLC. www.componentone.com