我在从csv粘贴到wpf数据网格时遇到了麻烦 - 我已经按照这里的建议进行了操作
并且代码exectues没有问题 - 但是,似乎创建了所有新行,但只有第一行填充了数据.数据似乎不断被覆盖,以便剪贴板数据中的最后一项填充在第一行,所有其他行都是空白.我知道这一定是一个索引问题,但我无法追踪它.
此外,当我查看网格的可绑定集合中的对象时,它们都没有任何数据.在列的OnPastingCellClipboardContent中是否存在某些错误(也许是数据转换)?
任何想法(见下面的代码)
protected virtual void OnExecutedPaste(object sender, ExecutedRoutedEventArgs args)
{
// parse the clipboard data
List<string[]> rowData = ClipboardHelper.ParseClipboardData();
bool hasAddedNewRow = false;
// call OnPastingCellClipboardContent for each cell
int minRowIndex = Math.Max(Items.IndexOf(CurrentItem), 0);
int maxRowIndex = Items.Count - 1;
int minColumnDisplayIndex = (SelectionUnit != DataGridSelectionUnit.FullRow) ? Columns.IndexOf(CurrentColumn) : 0;
int maxColumnDisplayIndex = Columns.Count - 1;
int rowDataIndex = 0;
for (int i = minRowIndex; i <= maxRowIndex && rowDataIndex < rowData.Count; i++, …
Run Code Online (Sandbox Code Playgroud)