Designning my own combobox

Hi, i'm developing my own control inherited from combobox class, but i have some problems with the dropdown, keydown behaviours. More exactly, when i press enter button in the smarthphone and a combobox have focus i don't want to shown all combobox items list to select one. I have made my own combo, something like this :

Public Class Class1
Inherits System.Windows.Forms.ComboBox

Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If (e.KeyCode = System.Windows.Forms.Keys.Enter) Then
MsgBox("hi")
Else
MsgBox("bye")
MyBase.OnKeyDown(e)
End If
End Sub

Public Sub New()
Me.Items.Add("Baseball")
Me.Items.Add("futbol")
Me.Items.Add("soccer")
Me.Items.Add("basketball")
End Sub
End Class

But, it isn't work correctly, i have supposed this component, after push enter key, will show the "hi" message and after this NOTHING, but, not .. when I press enter key .. my class show me the "hi" message and after this .. show me the combobox item list .. and theoretically, if i override a event in a inherited class .. why this works I must to declare a delegate, any ideas Please help me!!


Answer this question

Designning my own combobox

  • Rajesh batchu

    vTyphoon wrote:
    Hello ..
    I found the solution ..

    Public Class Class1
    Inherits System.Windows.Forms.ComboBox

    Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
    If (e.KeyCode = System.Windows.Forms.Keys.Enter) Then
    MsgBox("capullo")
    e.Handled = True
    Else
    MsgBox("gili")
    End If
    End Sub

    Public Sub New()
    Me.Items.Add("Baseball")
    Me.Items.Add("futbol")
    Me.Items.Add("soccer")
    Me.Items.Add("basketball")
    End Sub
    End Class

    I'm sorry but i haven't try this .. with this e.Handled = true the default delegate don't catch the event after my code ..

    Manuals in MSDN tell us that:

    .net framework Class Library

    Combox.OnKeyDown() event

    Event handle process will be invoked thru delegate when the event is triggered.

    OnKeyDown method accept that child class handles this event but not must thru delegate. And this is the first choice.

    Note for entenders: U must invoke base class's OnKeyDown method if u override OnKeyDown. It is because registered delegage can normally receive this event .



  • Mike Fulkerson

    Hi vtyphoon,

    Do you mean that u wana just show the "hi" message and after this NOTHING Of course you said so.

    But in fact, I have done the test as you offered and I found that it worked as you mentioned.

    But if you Add code:

    Me.DroppedDown = True

    after MsgBox("hi")

    Then it worked as you mentioned:"but, not .. when I press enter key .. my class show me the "hi" message and after this .. show me the combobox item list."

    Oh, I've done the test under VS Studio 2005 Pro.



  • kiwicoder2

    Hello ..
    I found the solution ..

    Public Class Class1
    Inherits System.Windows.Forms.ComboBox

    Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
    If (e.KeyCode = System.Windows.Forms.Keys.Enter) Then
    MsgBox("capullo")
    e.Handled = True
    Else
    MsgBox("gili")
    End If
    End Sub

    Public Sub New()
    Me.Items.Add("Baseball")
    Me.Items.Add("futbol")
    Me.Items.Add("soccer")
    Me.Items.Add("basketball")
    End Sub
    End Class

    I'm sorry but i haven't try this .. with this e.Handled = true the default delegate don't catch the event after my code ..

  • Designning my own combobox