核心提示:你是想获取总行数?还是选中行和列的索引?获取总行数:dataGridView1.Rows.Count;获取当前选中行索引:int i = this.dataGridView1.CurrentRow.I...
你是想获取总行数?还是选中行和列的索引?
获取总行数:dataGridView1.Rows.Count;
获取当前选中行索引:int i = this.dataGridView1.CurrentRow.Index;
获取当前选中列索引:int j = this.dataGridView1.CurrentCell.ColumnIndex;
//这是用鼠标从左上到右下方式选取的情况
int cellsCount = dataGridView1.SelectedCells.Count;
int c1 = (dataGridView1.SelectedCells[cellsCount-1].ColumnIndex);
int r1 = (dataGridView1.SelectedCells[cellsCount-1].RowIndex);
int c2 = (dataGridView1.SelectedCells[0].ColumnIndex);
int r2 = (dataGridView1.SelectedCells[0].RowIndex);
Console.WriteLine("选择了:第 {0} 列第 {1} 行 -- 第 {2} 列第 {3} 行",c1,r1,c2,r2);