I have a textbox and below it i have a listbox.
While the user is typing in the textbox if he presses the up or down arrow he should make a selection in the listbox. The textbox detects all the characters (except space) but it seems that it can't detect the arrow presses.
Any solution for this? This is a WPF project btw.
EDIT, Here's the working code thanks to T.Kiley:
    private void searchBox_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.IsDown && e.Key == Key.Down)
        {
            e.Handled = true;
            //do your action here
        }
        if (e.IsDown && e.Key == Key.Up)
        {
            e.Handled = true;
            //do another action here
        }
    }
I just tried this and it works. Add a preview key down event to the textbox
   private void TextBox_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
    {
        if (e.IsDown && e.Key == Key.Down)
            MessageBox.Show("It works");
    }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With