Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取DataGridView中选定单元格的行索引的快速方法_C#_Performance_Datagridview - Fatal编程技术网

C# 获取DataGridView中选定单元格的行索引的快速方法

C# 获取DataGridView中选定单元格的行索引的快速方法,c#,performance,datagridview,C#,Performance,Datagridview,我想获得DataGridView中选定单元格的行索引列表 我以前使用的是SelectedCells来获取此信息,但当有200万行且全部选中时,这需要大约40秒 this.SelectedCells .Cast<DataGridViewCell>() .Select(c => c.RowIndex) this.SelectedCells .Cast() .选择(c=>c.RowIndex) 上面说,SelectedCells对于大型网格来说速度很慢,但除了所

我想获得DataGridView中选定单元格的行索引列表

我以前使用的是
SelectedCells
来获取此信息,但当有200万行且全部选中时,这需要大约40秒

this.SelectedCells
    .Cast<DataGridViewCell>()
     .Select(c => c.RowIndex)
this.SelectedCells
.Cast()
.选择(c=>c.RowIndex)
上面说,
SelectedCells
对于大型网格来说速度很慢,但除了所有单元格都被选中的特殊情况之外,并没有提供很多替代方案。如果选择了除1行/单元格外的所有行/单元格怎么办


有更快的方法吗?

这是一个黑客攻击,但我最终还是恢复使用反射来访问私有字段
DataGridView.individualSelectedCells
,它是所选单元格的链接列表。这比访问DataGridView.SelectedCells要快得多,但显然不太可靠。

你的问题是什么?他想要一个比SelectedCells更快的替代品