Roxy'Pro
Roxy'Pro

Reputation: 4444

C# WPF KeyDown highlight + selected last row in datagrid

I'm working on application where user can add products to a datagrid, with simple informations like product name and price, and after that I would like to for example press F4 key on my keyboard and I would like to focus on last item in datagrid, that means select it and HIGHLIGHT that item!

So guys how could I achieve that, I've tried few solutions like setting selected index to my datagrid and smth like that, but it is not working

Thanks guys, Cheers

Upvotes: 0

Views: 1075

Answers (2)

Swifty
Swifty

Reputation: 1432

Where does your problem lie? With handling the button event or highlighting the row? It seems like its the latter, so have a look at this: https://www.codeproject.com/Tips/773382/Row-Highlighting-in-WPF-Grids

Upvotes: 0

Mighty Badaboom
Mighty Badaboom

Reputation: 6155

You can use an InputBinding to recognize the pressed F4 Key.

<Window.InputBindings>
    <KeyBinding Key="F4"
                Command="{Binding SelectLastItemCommand}" />
</Window.InputBindings>

You can have a look here for how to select the item: WPF Binding SelectedItem in DataGrid

Upvotes: 0

Related Questions