ShowDropDown with keyboard shortcuts

4 posts, 0 answers
  1. Seth
    Seth avatar
    4 posts
    Member since:
    Aug 2012

    Posted 09 Aug 2012 Link to this post

    With the default Microsoft combo box, you are able to use eithr Alt+Up or Alt+Down to toggle the drop down of the combo box.  I have tried to implement this functionality for the DropDownList control a couple of ways, but I am running into an issue.

    First:

    Private Sub RadDropDownList1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles RadDropDownList1.KeyDown
        If e.Alt And e.KeyCode = Keys.Down Then
            ' When the user presses both the 'ALT' key and 'arrow' key,
            'Drop down list
            e.Handled = True
            RadDropDownList1.ShowDropDown()
        End If
    End Sub

    I also tried:

    RadDropDownList1.DropDownListElement.ArrowButton.Shortcuts.Add(New RadShortcut(Keys.Alt, Keys.Down))

    I can get the drop down to toggle but in both cases the control still selects the next item in the list. Is there any way to get the control to toggle drop down state without selecting a new item from the list?

    Thanks

  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 13 Aug 2012 Link to this post

    Hi Seth,

    These key combinations are proceed in special manner and you cannot receive them in the KeyDownEvent.I can suggest using RadShortcut for your scenario. Please, refer to the code below:
    this.radDropDownList1.DropDownListElement.ArrowButton.Shortcuts.Add(new RadShortcut(Keys.Alt, Keys.Down));

    For more information about RadShortcut please read this help article: http://www.telerik.com/help/winforms/shortcuts-getting-started-(radmenuitems).html.

    All the best,
    Peter
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Seth
    Seth avatar
    4 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    I have tried using the RadShortcut to get the drop down to toggle. There are a couple of issues with this approach. The drop down will open as I would expect but it still selects the next item of you Alt+Down when the drop down is open. Also, if I have multiple drop down lists on the form it looks like only one can use the shorcut at a time. Is there a way for this to work for every drop down list control on the form?
  5. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 15 Aug 2012 Link to this post

    Hi Seth,

    I would like to propose another approach.

    Subscribe to the HostedTextBox KeyDown event and cancel the SelectedIndexChanging event in case that SelectedIndexChanged is caused by the KeyDown (Alt+Down) event:
    Private Sub Form1_Load( sender As System.Object,  e As System.EventArgs) Handles MyBase.Load
         AddHandler Me.RadDropDownList1.DropDownListElement.TextBox.TextBoxItem.HostedControl.KeyDown, AddressOf RadDropDownList1_KeyDown
     
    End Sub
    Dim shouldCancel As Boolean
     
    Private Sub RadDropDownList1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs)
            If e.Alt And e.KeyCode = Keys.Down Then
                ' When the user presses both the 'ALT' key and 'arrow' key,
                'Drop down list
                e.Handled = True
                RadDropDownList1.ShowDropDown()
                shouldCancel = True
            End If
        End Sub
     
        Private Sub RadDropDownList1_SelectedIndexChanging(sender As System.Object, e As Telerik.WinControls.UI.Data.PositionChangingCancelEventArgs) Handles RadDropDownList1.SelectedIndexChanging
            e.Cancel = shouldCancel
            shouldCancel = False
        End Sub

    I hope this helps.

    Greetings,
    Peter
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top