Custom ComboBox (Item Selection via Ctrl-Key)

FloLeBlanc

New member
Joined
Dec 6, 2005
Messages
1
Programming Experience
1-3
Hi!

I'm trying to build a custom combobox where items can be selected with the strg key (instead of arrow down).

The following code works for a ComboBox with "DropDown" Style, but not with "DropDownList" (which I need).
With DropDownList active the selected Value always changes back to the formerly selected one. The funny thing is - if I promt a msgbox in the "Leave" Event of the combobox, the correct value (the selected one) is kept.

I'd appreciate any ideas...

(combobox1.selectedIndex=0 is stated in the form where the box is used, otherwise an error would be thrown)

Public Class ComboBoxStrg Inherits System.Windows.Forms.ComboBox

Public Sub New()
AddHandler ComboBoxStrg.KeyDown, AddressOf ComboKeyDown
End Sub

Public Sub ComboKeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs)
If (e.KeyCode = 17) Then
If (Me.DroppedDown = False) Then
Me.DroppedDown = True
Else
Dim current As Integer =
Me.Items.IndexOf(Me.SelectedItem)
If (current + 1 >= Me.Items.Count) Then
Me.SelectedIndex = 0
Else
Me.SelectedIndex = current + 1
End If
End If
End If
End Sub

End Class
 

Attachments

Back
Top