This is a migrated thread and some comments may be shown as answers.

keypress on CommandBarDropDownList

3 Answers 124 Views
CommandBar
This is a migrated thread and some comments may be shown as answers.
ricric
Top achievements
Rank 1
ricric asked on 27 Feb 2011, 07:00 PM
i want to show messagebox by press enter on commandbardropdownlist, i use this code:

Private Sub CommandBarDropDownList1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles CommandBarDropDownList1.KeyDown
        If e.KeyCode = Keys.Enter Then
            MsgBox("hello", MsgBoxStyle.OkOnly)
        End If
    End Sub

but when i run it, there is nothing happened, is there something wrong with my code?

Thanks

3 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 27 Feb 2011, 07:29 PM
Hello ricric,

Do you have the DropDownStyle set to DropDown?
If so, then you'd need to add the event handler to the TextBoxItem which will work for you. Please consider the following code

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.CommandBarDropDownList1.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown
    AddHandler Me.CommandBarDropDownList1.DropDownListElement.TextBox.TextBoxItem.KeyDown, AddressOf CommandBarDropDownList1_KeyDown
End Sub
Private Sub CommandBarDropDownList1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
    If e.KeyCode = Keys.Enter Then
        MsgBox("hello", MsgBoxStyle.OkOnly)
    End If
End Sub

If you have further questions, or a different requirement, please let me know
Richard
0
ricric
Top achievements
Rank 1
answered on 28 Feb 2011, 01:41 AM
Ok, thanks for your help.
0
Richard Slade
Top achievements
Rank 2
answered on 28 Feb 2011, 10:42 AM
You're welcome. If you need anything further please let me know
Richard
Tags
CommandBar
Asked by
ricric
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
ricric
Top achievements
Rank 1
Share this question
or