How can I check the Ctrl keypress on the keyboard?

I currently have this code:

        DataGrid.SelectionChanged += new SelectionChangedEventHandler(DataGrid_SelectionChanged);

        private void DataGrid_SelectionChanged(object sender, EventArgs e)
        {
            if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
            {
                //do stuff
            }
        }

The code checks the Ctrl button when the selection in the data grid changes, which works fine for detecting the Ctrl key for regular physical keys, but when I use the on-screen keyboard and press the Ctrl key, it does not register in my program. The root of this code is that you cannot Ctrl + click rows in a Datagrid in WPF when you use the Ctrl key on the on-screen keyboard.

Edit: It seems to satisfy the if condition if I press ctrl on the on-screen keyboard and then β€œA” (which selects everything). None of the other shortcuts (ctrl + c, ctrl + v does not trigger this answer)

+4
source share
1 answer

datagrid. ctrl + click shift + click, , , . , "".

+1

All Articles