I would like to let the client input numeric, "," and "-" in the
textbox,
all the other else charater will take no effect on the value of the
textbox.
How can I do so?
Thanks a lot!
rowe_newsgroups - 05 Jul 2007 11:24 GMT
> I would like to let the client input numeric, "," and "-" in the
> textbox,
[quoted text clipped - 4 lines]
>
> Thanks a lot!
The "standard" way is to handle the textbox's keydown, keypress, or
keyup events and trap the invalid keys there and prevent them from
going into the textbox. You may also have to trap paste events - it's
been a while and I don't remember if the above will catch pasted text
or not.
Thanks,
Seth Rowe
Cor Ligthert [MVP] - 05 Jul 2007 11:43 GMT
Hi,
You can search this newsgroup with this problem,
http://groups.google.nl/group/microsoft.public.dotnet.languages.vb/search?group=
microsoft.public.dotnet.languages.vb&q=numeric+textbox
There you will find the solution as Seth has written.
Cor
>I would like to let the client input numeric, "," and "-" in the
> textbox,
[quoted text clipped - 4 lines]
>
> Thanks a lot!
Mr. Arnold - 05 Jul 2007 11:49 GMT
>I would like to let the client input numeric, "," and "-" in the
> textbox,
[quoted text clipped - 4 lines]
>
> Thanks a lot!
You put something like the code below in the Textbox Keydown event
If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
'cancel keys
e.Handled = True
End If
Mr. Arnold - 05 Jul 2007 11:54 GMT
>>I would like to let the client input numeric, "," and "-" in the
>> textbox,
[quoted text clipped - 4 lines]
>>
>> Thanks a lot!
Sorry, that would be put in the Textbox KeyPress event is the right place.
> If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
> AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
> 'cancel keys
> e.Handled = True
> End If
Cylix - 06 Jul 2007 02:29 GMT
Sorry about such silly question,
I just don't know that I can done the task by e.handled = true.
Thanks a lot.