Stop CTRL-Click from affecting the parent datagrid

I have a WPF DataGrid that has another datagrid declared in a RowDetailsTemplate;

<DataGrid name="dataGrid1" RowDetailsVisibilityMode="VisibleWhenSelected"> ... <DataGrid.RowDetailsTemplate> <DataTemplate> <DataGrid name="dataGrid2"> ... </DataGrid/> </DataTemplate> </DataGrid.RowDetailsTemplate> </DataGrid> 

When I CTRL-click a row on a child DataGrid, it does not select the parent datagrid SelectedItem and hides the RowDetailsTemplate .

I assume this is some kind of behavior related to a routed event, but I tried to catch MouseDown / LeftButtonMouseDown in a datagrid, but no event was fired. I also caught the SelectedItemChanged event on the child datagrid and set e.Handled = true; but the event is still fired on the parent.

How can I stop the parent datagrid from unselecting when CTRL -Click on the child DataGridRow?

+4
source share
1 answer

Catching PreviewMouseLeftButtonDown in a child control, setting e.Handled = true and dataGridRow.IsSelected = !dataGridRow.IsSelected fixed.

+2
source

Source: https://habr.com/ru/post/1397716/


All Articles