Replace a character in combo box

K

Kay

Hi All,

I'm trying to write a small sub/function to replace some (invalid) character
in a combo box, or may be even text box. For example, I have several combo
boxes that allows user to select a time value, i.e. 21:30, however I also
want to allow them to enter a time, as a result I want to replace comma,
fullstop etc with a colon ":". I've done this in VB6 keypress event,
however with the "sender", "e" in .net I'm a bit lost... I don't have much
experience in .net could you guys give me some help?

Thanks!

Kay
 
K

Kay

Hi Cor & all,

Core thanks for your response, I have a look on your web site, but I think
it may be a bit difficult if I want to use it for a text box - after I think
again what I really want - if it's possible I want to create a function,
with a papramater, then check whether it's a valid character, i.e. in this
case ":" & number are valid, if not cancel the character entered, or replace
with other character....um... that sounds good to me but if you guys have a
better advice please tell me!! So now the problem I have is how to capture
the character just entered....

Kay
 
C

Cor Ligthert [MVP]

Kay,

Have a look at the thenthousand samples about a numeric textbox on Internet
by using Google.

I have not set this one on our site, because there is nothing in it for
pushing the del key etc.
Especially for your question, use the keyup event most people want to use
the key down, which gives less information in the KeyEventArgs.

\\\\
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.MaxLength = 10
End Sub
Private Sub textbox1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles textbox1.KeyUp
If e.KeyValue <> 8 Then
If Not IsNumeric(TextBox1.Text) Then
If TextBox1.Text.Length > 0 Then
MessageBox.Show("Only numeric is allowed")

TextBox1.SelectionStart = TextBox1.Text.Length - 1
TextBox1.SelectionLength = 1
End If

End If
End If
End Sub
///

I hope this helps,

Cor
 
K

Kay

Hi Cor,

Thanks for your help! Can I ask one more question? :p

Is there something like an ASCII table that represent a KeyValue? Coz I
want to capture more characters other than numbers. Tried to search through
the help but it didn't tell much.... may be I'm looking at the wrong
direction...

Kay
 
C

Cor Ligthert [MVP]

Kay,

No I thought you know that, you see in the latest sample the 8 but there are
more therefore I said it was not complete.

Therefore I said have a look for a numeric textbox

This is a nice solution with the control characters
http://groups.google.com/group/microsoft.public.dotnet.languages.vb/msg/6ff7a8450e71ebf6

I took from Internet the first table I could find. I know that there is a
nicer one on MSDN, but with the same search information I could not find it
there, maybe you can try that yourself.

http://www.lookuptables.com/

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top