1
votes

Right after loading a WPF DataGrid, I hit the 'Select All Button' (upper left hand corner) followed by Control-C.

But this sequence does not copy the datagrid items to my clipboard.

How can I make this work?

1

1 Answers

3
votes

It seems data grid does not focus itself when that button is clicked, so you have to fix it yourself:

dataGrid.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, OnDataGridSelectAll));

And then:

private void OnDataGridSelectAll(object sender, ExecutedRoutedEventArgs e) {
    var grid = (DataGrid)sender;
    grid.Focus();
    grid.SelectAll();
}

You can also add command binding in xaml if you want so.