0

I'm using a standard data grid defined below. The itemssource is bound in the code behind after some calculations are done.

        <DataGrid Name="TimeDataGrid" Block.TextAlignment="Center" FontSize="14" SelectionMode="Extended" SelectionUnit="Cell" ClipboardCopyMode="ExcludeHeader" AutoGeneratingColumn="OFMDataGrid_AutoGeneratingColumn">
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="Copy"/>
                </ContextMenu>
            </DataGrid.ContextMenu>
                <DataGrid.InputBindings>
                    <KeyBinding Key="C" Modifiers="Control" Command="Copy" />
                </DataGrid.InputBindings>
         </DataGrid>

The problem I am having is related to copying the data. When I ctrl+A to select all cells and the right-click, copy, it will select the data and add it to the clipboard. However, if I use ctrl+c, nothing gets put to the clipboard.

This is my first time posting here and I have read just about every suggestion ranging from the simplest adding of the applicationcommands to modifying oncopytoclipboard type events and nothing seems to work. I feel like I am missing something that should be obvious.

Thank you to anyone who can help.

Tim Dash
  • 1
  • 1
  • See if this helps: http://stackoverflow.com/a/12943306 – Xiaoy312 Aug 18 '16 at 20:43
  • You need to make sure that your Keyborad Focus is on your desired place. I am not sure how is that. But I am 100% sure it is something related to Where the Keyboard Focus is. – Khalil Khalaf Aug 18 '16 at 20:43
  • Something like this http://stackoverflow.com/questions/12866392/wpf-setting-keyboard-focus-in-a-user-control-problems-with-keybinding – Khalil Khalaf Aug 18 '16 at 20:49
  • Shoot. Neither seem to resolve the issue. Still nothing is being sent to the Clipboard even after setting the keyboard focus – Tim Dash Sep 01 '16 at 13:01

1 Answers1

0

Try this:

<!-- This is required to handle CTRL + C when something is selected in the DataGrid -->
    <DataGrid.CommandBindings>
        <CommandBinding Command="Copy" Executed="CopyCommand" />
    </DataGrid.CommandBindings>

    <!-- This is required to handle CTRL + C when something is selected in the DataGrid -->
    <DataGrid.InputBindings>
        <KeyBinding Key="C" Modifiers="Control" Command="Copy" />
    </DataGrid.InputBindings>
gnarpo
  • 31
  • 3