ComboBox problem handling SelectedIndexChanged event and keypress events

D

dule

Hi all,

How to enable that in combobox user can change the selection with Up and
Down keys without firing the SelectedIndexChanged event and also that
pressing the Enter on the keyboard responds in the same way as the clicking
on the combo?
I have tried with various combinations RemoveHandler and AddHandler but so
far without success!

Please help,
Thx
Dule
 
D

dule

This is the best solution that I have managed to do by now and is there some
better way to do this?

Private Sub cmbUlic_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles cmbUlic.KeyDown

blType = False 'global variable that is set to true if the Up and Down keys
were pressed

nonNumberEntered = False

If e.KeyCode < Keys.Up And e.KeyCode > Keys.Up Then 'check if the Up or
Down keys on the hardware keyb were pressed

If e.KeyCode <> Keys.Enter Then

nonNumberEntered = True

End If

End If

If e.KeyCode = Keys.Up OrElse e.KeyCode = Keys.Down Then

blType = True

End If

End Sub

Private Sub cmbUlic_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles cmbUlic.KeyPress

If AscW(e.KeyChar) <> Keys.Enter Then 'Again I have to check for the
'Enter' because the soft keyb. only fires KeyPress event

e.Handled = True

Else

cmbUlic_SelectedIndexChanged(sender, e)

End If

End Sub

Private Sub cmbUlic_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbUlic.SelectedIndexChanged

If blType Then

blType = False

Exit Sub

End If

' do something else

end sub
 

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