469,920 Members | 2,209 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,920 developers. It's quick & easy.

Insert key press in text box

Hi all

I am making a program whereby when the insert key is pressed in a text
box it opens up another form with the search parameters they entered in
the text box and automatically searches for the data. I have the code
below however it does not work when i press the insert key. I have
tried it with the enter key Ascii code 13 and all works fine! Is it
something to do with Insert being a system/bios key? My code is below;

Private Sub TelephoneTxt_KeyPress(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyPressEventArgs) Handles
TelephoneTxt.KeyPress
'handle telphone number search
Dim key As Char = Microsoft.VisualBasic.ChrW(45)
If e.KeyChar = key And TelephoneTxt.Text = "" And
SurnameTxt.Text = "" Then
MsgBox("Please enter at least one of the two search
parameters")
ElseIf e.KeyChar = key Then
CustomerSearch.ShowDialog()
CustomerSearch.CustomerReservationSearch(SurnameTx t.Text,
TelephoneTxt.Text)
End If
End Sub
Any help is much appreciated

Thanks

James

Dec 5 '06 #1
3 3181
"jimmy" <ja**************@tiscali.co.ukwrote in message
news:11*********************@16g2000cwy.googlegrou ps.com...
Hi all

I am making a program whereby when the insert key is pressed in a text
box it opens up another form with the search parameters they entered in
the text box and automatically searches for the data. I have the code
below however it does not work when i press the insert key. I have
tried it with the enter key Ascii code 13 and all works fine! Is it
something to do with Insert being a system/bios key? My code is below;

Private Sub TelephoneTxt_KeyPress(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyPressEventArgs) Handles
TelephoneTxt.KeyPress
'handle telphone number search
Dim key As Char = Microsoft.VisualBasic.ChrW(45)
If e.KeyChar = key And TelephoneTxt.Text = "" And
SurnameTxt.Text = "" Then
MsgBox("Please enter at least one of the two search
parameters")
ElseIf e.KeyChar = key Then
CustomerSearch.ShowDialog()
CustomerSearch.CustomerReservationSearch(SurnameTx t.Text,
TelephoneTxt.Text)
End If
End Sub
Any help is much appreciated

Thanks

James
James,

The KeyPress event doesn't fire for the insert key, as it doesn't produce a
character (e.KeyChar).
You can use the KeyDown or KeyUp event to trap the Insert key;

Private Sub TelephoneTxt_KeyDown(ByVal sender As Object, ByVal e As System.
_
Windows.Forms.KeyEventArgs) Handles TelephoneTxt.KeyDown
' Handle telphone number search
If e.KeyCode = Keys.Insert And TelephoneTxt.Text = "" And
SurnameTxt.Text = "" Then
MsgBox("Please enter at least one of the two search parameters")
ElseIf e.KeyCode = Keys.Insert Then
CustomerSearch.ShowDialog()
CustomerSearch.CustomerReservationSearch(SurnameTx t.Text,
TelephoneTxt.Text)
End If
End Sub

Hope that helps.
_____________________________
The Grim Reaper
Dec 5 '06 #2
On 5 Dec 2006 12:12:27 -0800, jimmy wrote:
Private Sub TelephoneTxt_KeyPress(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyPressEventArgs) Handles
TelephoneTxt.KeyPress
'handle telphone number search
Dim key As Char = Microsoft.VisualBasic.ChrW(45)
If e.KeyChar = key And TelephoneTxt.Text = "" And
SurnameTxt.Text = "" Then
MsgBox("Please enter at least one of the two search
parameters")
ElseIf e.KeyChar = key Then
CustomerSearch.ShowDialog()
CustomerSearch.CustomerReservationSearch(SurnameTx t.Text,
TelephoneTxt.Text)
End If
End Sub

Any help is much appreciated

Thanks

James
Hey james,

Try the KeyDown event instead

--
Bits.Bytes
http://bytes.thinkersroom.com
Dec 5 '06 #3
Thanks to both you guys!

Dec 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Gunnar Kristiansen | last post: by
1 post views Thread by tshad | last post: by
reply views Thread by Brenton Garman | last post: by
1 post views Thread by Chris | last post: by
3 posts views Thread by Mukesh | last post: by
1 post views Thread by skanemupp | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.