2012-06-14 38 views
4

我正在使用WPF DataGrid来显示名称 - 值对。 SelectionUnit设置为FullRow,因为它看起来不错,但是,当用户选择行并按下Ctrl键+ç真正想要的值复制文本,而不是它的名称和值的串联的默认行为。在寻找解决方案时,我发现CopyingRowClipboardContent事件,但the MSDN page没有关于如何使用它的信息。或者我应该自己捕获PreviewKeyDown在WPF DataGrid中自定义Ctrl + C行为

回答

2

您可以使用DataGridRowClipboardEventArgs修改的CopyingRowClipboardContent事件处理程序中复制数据。

反编译源代码

public class DataGridRowClipboardEventArgs 
{ 
    /// <summary> 
    /// This list should be used to modify, add or remove a cell 
    /// content before it gets stored into the clipboard. 
    /// </summary> 
    public List<DataGridClipboardCellContent> ClipboardRowContent 
    { 
     ... 

因此,举例来说,如果你有两列,你只需要第一,你可以删除这样的第二项:

private void grid_CopyingRowClipboardContent(
    object sender, DataGridRowClipboardEventArgs e) 
{ 
    e.ClipboardRowContent.RemoveAt(1); 
} 
0

也许这是你在找什么

ClipboardCopyMode = DataGridClipboardCopyMode.ExcludeHeader;

+0

不,那是排除列标题,我想要的是排除行中的某些单元格。 –