I am working on a uwp app. In that I am using a data grid from https://github.com/MyToolkit/MyToolkit/wiki/DataGrid here. Now in this I have to use keyboard actions using up and down arrows.
I have used KeyDown event and selection_changed event for first item only keydown event is firing. then selection_changed event is firing when up and down arrow keys pressed. But I want to do some action when enter key pressed after selecting a row in the grid. the code I have used is:`
private void dgsuggestion_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
}
}
private void dgsuggestion_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ProductsList res= (ProductsList)((MyToolkit.Controls.DataGrid)sender).SelectedItem;
selectedsku = res;
}`
Can anyone help me..
The events get absorb by either the system or the control, so you have to attach the event manually using AddHandler
.
MyToolkit.Controls.DataGrid myGrid; // this is your grid
// Do this
myGrid.AddHandler(KeyDownEvent, new RoutedEventHandler(dgsuggestion_KeyDown), true);
// Not this
myGrid.KeyDown += dgsuggestion_KeyDown;
Here's an explanation of how it works.
https://msdn.microsoft.com/en-us/library/ms598899(v=vs.110).aspx