Suk*_*nya 7 c# datagrid gridview
我有一个datagrid/gridview.我最初用10行填充网格.每按一次按钮,我就会继续向datagrid/gridview添加10行.现在我想在每次填充网格时将焦点设置到最后一行.我可以获得该行的索引,但我无法将焦点设置为该特定行.
你们其中任何人都知道如何在C#中做到这一点吗?
Wae*_*oul 14
试试这个
dataGridView1.ClearSelection();
int nRowIndex = dataGridView1.Rows.Count - 1;
dataGridView1.Rows[nRowIndex].Selected = true;
dataGridView1.Rows[nRowIndex].Cells[0].Selected = true;
Run Code Online (Sandbox Code Playgroud)
对于WinForms DataGridView:
myDataGridView.CurrentCell = myDataGridView.Rows[theRowIndex].Cells[0];
Run Code Online (Sandbox Code Playgroud)
对于WebForms GridView,请使用SelectedIndex属性
myGridView.SelectedIndex = theRowIndex;
Run Code Online (Sandbox Code Playgroud)