c# 获取dataGridView选中行的行数
的有关信息介绍如下:获取总行数:dataGridView1.Rows.Count;
获取当前选中行索引:int i = this.dataGridView1.CurrentRow.Index;
获取当前选中列索引:int j = this.dataGridView1.CurrentCell.ColumnIndex
List selectedRowsIndex = new List();
List selecteRows = new List();
foreach(DataGridViewRow r in this.dataGridView1.Rows)
{
foreach (DataGridViewCell c in r.Cells)
if (c.Selected && !selectedRowsIndex.Contains(c.RowIndex))
{
selectedRowsIndex.Add(c.RowIndex);
selecteRows.Add(r);
}
}if (selectedRowsIndex.Count > 1)
{
if (MessageBox.Show("确定删除" + selectedRowsIndex.Count.ToString() + "行数据吗?", "删除前确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
foreach (DataGridViewRow r in selecteRows)
this.dataGridView1.Rows.Remove(r);
}
}