1

Is there a way to navigate through a ComboBox elements when dropped down using arrow keys ? I am searching through items from an SQL server and they are displayed but I want to traverse through them using the keyboard instead of the mouse. I tried something like that but it didn't work :

private void StackPanel_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Down)
    {
        ComboBox = e.Source as ComboBox;
        if (s != null)
        {
            s.MoveFocus(new TraversalRequest( FocusNavigationDirection.Next));
        }

        e.Handled = true;
    }
}

Xaml : <ComboBox1 PreviewKeyDown="StackPanel_PreviewKeyDown" />

Code source from : Moving to next control on Enter keypress in WPF

Here is the combobox : enter image description here

A minor detail, also is there away to remove the highlight from the typed letter ? In this case the letter "e" as displayed in the screen shot. Thank you so much in advanced I would really appreciate it if you could help me.

Community
  • 1
  • 1
Little Programmer
  • 181
  • 1
  • 5
  • 15

1 Answers1

0

The code works perfectly fine the mistake was once I click the down/up arrow key the focus is set to the next/previous item and displays its values that's why it disregards the other, it's like once you set focus on the item as if you selected it !

Little Programmer
  • 181
  • 1
  • 5
  • 15