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

ShowDropDown with keyboard shortcuts

3 Answers 621 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 09 Aug 2012, 12:53 PM

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

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 13 Aug 2012, 12:07 PM
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 >>
0
Seth
Top achievements
Rank 1
answered on 13 Aug 2012, 12:32 PM
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?
0
Peter
Telerik team
answered on 15 Aug 2012, 01:44 PM
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 >>
Tags
DropDownList
Asked by
Seth
Top achievements
Rank 1
Answers by
Peter
Telerik team
Seth
Top achievements
Rank 1
Share this question
or