简体   繁体   English

如何在WPF Datagrid中实现复制

[英]How to implement Copy in WPF Datagrid

I am trying to implement a Copy operation for a datagrid configured with 我正在尝试为配置有以下内容的数据网格实施复制操作

SelectionMode="Extended"
SelectionUnit="Cell"

I have figured out (mostly) how to get content from the cells in the DataGrid.SelectedCells collection - Text columns, Combobox columns, and Templated columns. 我已经弄清楚(主要是)如何从DataGrid.SelectedCells集合的单元格中获取内容-文本列,组合框列和模板列。 Determining how many columns are involved seems pretty straightforward: 确定涉及多少列似乎很简单:

var cols = selectedCells.Select(c => c.Column.DisplayIndex).Distinct().ToList();
Debug.WriteLine($"Found {cols.Count} columns.");

However, I can't figure out if the cells are on different rows. 但是,我不知道这些单元格是否在不同的行上。 I think I need that information to use appropriate separators between cells to indicate multiple rows. 我想我需要该信息以在单元格之间使用适当的分隔符来指示多行。 DataGrid.SelectedCells is an DataGrid.SelectedCells是一个

IList<DataGridCellInfo>

The DataGridCellInfo has an DataGridCellInfo具有一个

object Item

property, which is an item in the collection the datagrid is bound to. 属性,它是datagrid绑定到的集合中的一项。 I don't think that helps... 我认为这没有帮助...

Any ideas or pointers would be appreciated, thanks. 任何想法或指示,将不胜感激,谢谢。

您应该能够使用DataGrid.Items.IndexOf(cell.Item)检索行索引,其中cellDataGridCellInfo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM