Hi,
I have WPF 4 desktop-based application. In one of the windows of this application I have DataGrid with data, binded with SQL Server database (via ADO.NET Entity Framework). In order to manipulate with data I have delete button, that deletes selected row from DataGrid and call SaveChanges()
method.
Now I want to add support for keyboard manipulations, e.g. i want to let user to remove row by selecting and clicking on Delete keyboard button.
If I set CanUserDeleteRows="True"
in window's XAML, it removes selected row, but doesn't make commit to database, in other words, it doesn't call SaveChanges()
method.
I tried to add keyDown event handler to DataGrid an check if (e.Key == Key.Delete)
, so run remove method that removes selected row and call SaveChanges()
method, but it doesn't work.
My question is how can I add keyboard event handler to DataGrid that will let remove selected row and call SaveChanges()
method or just run my own method, that deals with row removing from DataGrid and make commit to DB.
Of course, if you have any other idea, relatred to my question, feel free to suggest.
Thanks.