keypress on CommandBarDropDownList

4 posts, 1 answers
  1. ricric
    ricric avatar
    12 posts
    Member since:
    Sep 2010

    Posted 27 Feb 2011 Link to this post

    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
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 27 Feb 2011 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. ricric
    ricric avatar
    12 posts
    Member since:
    Sep 2010

    Posted 27 Feb 2011 Link to this post

    Ok, thanks for your help.
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 28 Feb 2011 Link to this post

    You're welcome. If you need anything further please let me know
    Richard
Back to Top