title: How do I override WPF DataGrid behaviour to implement Drag and Drop to an external application?
body: <p>I have a WPF DataGrid with the following definition.</p>
  
  <pre><code>&lt;DataGrid Name="DataGridFoo"
    AutoGenerateColumns="False"
    ItemsSource="{Binding GridData}"
    IsReadOnly="True"
    SelectionMode="Extended"
    SelectionUnit="CellOrRowHeader"&gt;
  </code></pre>
  
  <p>This allows me to have the user selected a "region" of cells. The DataGrid is bound to an observable collection. The XAML column definitions have some columns hidden, some visible like this:</p>
  
  <pre><code>&lt;DataGridTextColumn Binding="{Binding InvoiceID}"
     Header="Invoice ID"
     Visibility="Hidden"
     Width="Auto"/&gt;                
  &lt;DataGridTextColumn Binding="{Binding InvoiceNumber}"
     Header="Invoice Number"
     Visibility="Visible"
     Width="Auto"/&gt;
  &lt;DataGridTextColumn 
     Binding="{Binding InvoiceDate, StringFormat=\{0:MM/dd/yy\}}"
     Header="Invoice Date"
     Visibility="Visible"
     Width="Auto"/&gt;
  </code></pre>
  
  <p>I also have a Right Mouse Button context menu defined for the DataGrid:</p>
  
  <pre><code>&lt;DataGrid.ContextMenu&gt;
    &lt;ContextMenu FontSize="16"  Background="#FFE6E9EC"&gt;
      &lt;MenuItem Header="Contact" Click="Contact_Click" /&gt;
      &lt;Separator  /&gt;
      &lt;MenuItem Header="Copy" Command="Copy" /&gt;
    &lt;/ContextMenu&gt;
  &lt;/DataGrid.ContextMenu&gt;
  </code></pre>
  
  <p>I would like to be able to Click, Drag and Drop a copy of the currently selected cells into an external application. I was thinking of using the combination of pressing the "Alt Key" and Left Mouse Button click to initiate the DragDrop operation.</p>
  
  <p><strong>For example, consider the "irregular" selection of cells in the DataGrid:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/cvSx4.png" rel="noreferrer"><img src="https://i.stack.imgur.com/cvSx4.png" alt="enter image description here"></a></p>
  
  <p><strong>I am unclear on how to proceed and have several questions regarding this:</strong></p>
  
  <p><strong>1)</strong> What events do I override so that the /Left Mouse click do not affect the currently selected cells?</p>
  
  <p><strong>2)</strong> How do I determine whether the Left Mouse Button click is occurring within a region of selected cells? How do I handle the data piece?</p>
  
  <p><strong>3)</strong> Once I've determined the above, what is the next step? Do copy data into the clipboard for use on the external drop?</p>
  
  <p><strong>4)</strong> What events (if any) do I need to override on the DataGrid in order for this to work?</p>
  
  <p>Thanks</p>