如何在C#中使用单元格选择作为选择模式来获取选定的行数?
在这里,我可以像这样检索所选单元格的信息如何在C#中使用单元格选择作为选择模式来获取选定的行数?,c#,datagridview,windows-forms-designer,C#,Datagridview,Windows Forms Designer,在这里,我可以像这样检索所选单元格的信息 DataGridViewCell selectedCell = productSpecGrid.SelectedCells[0]; int rowIndex = selectedCell.RowIndex; int colIndex = selectedCell.ColumnIndex; 接下来,我的目标是获得选定的行数,而不是单元格,只是行数 我就是这样尝试的: int count = 0; for (int i = 0; i < produc
DataGridViewCell selectedCell = productSpecGrid.SelectedCells[0];
int rowIndex = selectedCell.RowIndex;
int colIndex = selectedCell.ColumnIndex;
接下来,我的目标是获得选定的行数,而不是单元格,只是行数
我就是这样尝试的:
int count = 0;
for (int i = 0; i < productSpecGrid.SelectedRows.Count; i++)
{
count++;
}
MessageBox.Show(count.ToString());
int count=0;
for(int i=0;i
测试
输出
问题
使用特定的单元格选择作为我的选择模式。如何获得所选每行的计数
编辑
看看这里:
它声明:使用SelectedRows属性。要使用户能够选择行,必须将SelectionMode属性设置为FullRowSelect或RowHeaderSelect。
这就是我在输出中得到0
的原因
编辑2
我在这里找到了答案:
只是不确定他指的是
您可以选择呼叫计数
for(int i=0;i
-.这是否回答了您的问题@GSerg Hi,我想特别使用Cell Select
而不是Full Row
,他的意思是:var count=productSpecGrid.SelectedCells.Cast().Select(c=>c.RowIndex.Distinct().count()代码>。你好:)@dr.null谢谢:)for(int i=0;i
-。这回答了你的问题吗@GSerg Hi,我想特别使用Cell Select
而不是Full Row
,他的意思是:var count=productSpecGrid.SelectedCells.Cast().Select(c=>c.RowIndex.Distinct().count()代码>。你好:)@dr.null谢谢:)