如何把dataGridView中的某一行指定為當前行。
datagridview.rows[i].setCurrentrow.
也就是讓光標指到那一行去。
如何做呢?
------解决方案--------------------\\ex:
int currentrowid = 7;
dataGridView1.CurrentCell = dataGridView1.Rows[currentrowid].Cells[1];
------解决方案--------------------首先把SelectionMode属性设为FullRowSelect
int i = 3; //待选中行索引
if (dataGridView3.Rows.Count > i)
{
//清除当前行选中状态
for (int j = 0; j < dataGridView3.SelectedRows.Count; j++)
{
dataGridView3.SelectedRows[j].Selected = false;
}
dataGridView3.Rows[i - 1].Selected = true;
}
------解决方案-------------------- 如下:
首先设置dataGridView的SelectionMode值为FullRowSelect,MultiSelect值为false.
dataGridView1.Rows[index].Selected = true; // index为要设置活动行的索引