Click here to Skip to main content
15,911,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I have problems with focus gridView item after up/down button (from keyboard) pressed.
I have textbox with textchanged event, so when i change text, it's looking for items in datagrid which contains textbox.text - that work's great. But now, when i press up/down arrow i'd like to focus first element of dataGrid.
So in code it should be something like:

C#
private void Window_PreviewKeyDown_1(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Down || e.Key == Key.Up)
            {
//raise only when nothing is selected, otherway just move selection item in gridview up/down
                if(myDG.SelectedItem == null)
                    myDG.SelectedIndex = 0;
            }
        {


And actually I can see that it's getting selected, but item background is gray, not blue.

Thanks for any help!
Posted
Updated 5-Jul-13 1:41am
v2

1 solution

Hello!

Did you try get focus on it first?
C#
myDG.Focus();
myDG.SelectedIndex = 0;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900