【发布时间】:2014-02-18 01:21:51
【问题描述】:
在 WPF DataGrid 中,我尝试使用以下代码选择给定列中的所有单元格
for (int i = 0; i < MyDataGrid.Items.Count; i++)
{
MyDataGrid.SelectedCells.Add(new DataGridCellInfo(MyDataGrid.Items[i], column));
}
不过,这段代码运行速度极慢。
MyDataGrid.Items 是 ItemCollection<MyDataStructure> 类型,包含大约 70,000 个项目。
MyDataGrid.SelectedCells 的类型为 IList<DataGridCellInfo>。
整个循环大约需要 30 秒。
有人可以解释为什么需要这么长时间吗? 另外,是否可以将其交换为 LINQ 查询?
【问题讨论】: