KeyEventArgs

  • Thread starter Dino Buljubasic
  • Start date
D

Dino Buljubasic

can somebody help me please with this simple problem?

I have combo box with numbers for months in it and want user to be
able to select a month Say 3 (for March) simply by clicking a number
either from the top row of keyboard or from numeric keypad.

So far I got this work for the top row (numbers) on the keyboard but I
can not get it to work for selected number from numeric keypad.

I do this:

for top row (numbers)
if e.KeyCode >= Keys.D1 And e.KeyCode <= Keys.D9 then
strKey as String = chrW(e.KeyData)
end if

for numeric keypad
if e.keyCode >= Keys.NumPad1 and e.KeyCode <= Keys.NumPad9 then
strkey as String = ?????

Thank you,
Dino
 
G

Guest

Here's your solution:

Start a new Windows application & add a combobox (ComboBox1) to your form

Now, paste in the code below:

Const WM_KEYDOWN As Integer = &H100

Protected Overrides Function ProcessCmdKey _
(ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) As Boolean

If msg.Msg = WM_KEYDOWN Then
Return Not (keyData >= Keys.NumPad0 And keyData <= Keys.NumPad9) _
AndAlso Not (keyData >= Keys.D0 And keyData <= Keys.D9)
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function

-----------------------

It only allows you to type in numbers abover the QWERTY... & from the
numeric pad.

I hope this helps
 
D

Dino Buljubasic

Here's your solution:

Start a new Windows application & add a combobox (ComboBox1) to your form

Now, paste in the code below:

Const WM_KEYDOWN As Integer = &H100

Protected Overrides Function ProcessCmdKey _
(ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) As Boolean

If msg.Msg = WM_KEYDOWN Then
Return Not (keyData >= Keys.NumPad0 And keyData <= Keys.NumPad9) _
AndAlso Not (keyData >= Keys.D0 And keyData <= Keys.D9)
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function

-----------------------

It only allows you to type in numbers abover the QWERTY... & from the
numeric pad.

I hope this helps
 
D

Dino Buljubasic

Hi,

thank you for your help. However, I need to get the value, not just
to check for it. I know how to check for the keys, what I need is the
value (e.g if D2 or NumPad2 then 2) so I can then select the 2nd
month.

I have several combo boxes on the form, some of which are dealing with
Strings (e.g. names of countries) which I am processing just fine, and
the others dealing with numbers (e.g. months). I process these fine
as well but only for numbers above QUERTY. What I need is the way to
do it for numeric keypad, too.

Here is the code I am using so far:

Private Sub WcboMonth_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles WcboMonth.KeyUp
If ((e.KeyCode >= Keys.D1) And (e.KeyCode <= Keys.D9)) Then

// THIS WORKS FINE
Dim strString As String = ChrW(e.KeyData)
Dim index As Integer = 0

Dim i As Integer = 0
For i = 0 To WcboMonth.Items.Count - 1
If (WcboMonth.Items(i).Text.Chars(0) =
strString) Then
index = i
Exit For
End If
Next

WcboMonth.SelectedIndex = index
End If


If ((e.KeyCode >= Keys.NumPad1) And (e.KeyCode <=
Keys.NumPad9)) Then

// THIS DOES NOT WORK (e.g. returns 'e' instead of 5)
Dim strString As String = ChrW(e.KeyData)
Dim index As Integer = 0

Dim i As Integer = 0
For i = 0 To WcboMonth.Items.Count - 1
If (WcboMonth.Items(i).Text.Chars(0) =
strString) Then
index = i
Exit For
End If
Next

WcboMonth.SelectedIndex = index
End If
End Sub

Any suggestions?

thank you
_dino_
 
D

Dino Buljubasic

Thank you for your help.

I find the way how to do this. For those interested, I used wrong
event handler. I used KeyUp instead of using KeyPress (... I know,
one of these things ...)

Anyways, use KeyPress instead of KeyUp or so and then you have
e.KeyChar available which will return you the character pressed no
matter wehter you are using numeric pad, or numbers above QUERTY.

_dino_
 

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