我有一个datagridview接受一个(myObject)列表作为数据源。我想在datagrid中添加一个新行以添加到数据库中。我通过获取列表来完成此操作...将空白myObject添加到列表中,然后重置数据源。我现在想要将焦点设置为新行中的第二个单元格。
要CLARIFY我正在尝试设置焦点
答案 0 :(得分:4)
您可以将焦点设置为行中的特定单元格,但前提是DataGridView上的SelectionMode设置为CellSelect。如果是,只需执行以下操作:
dataGridView.Rows[rowNumber].Cells[columnNumber].Selected = true;
答案 1 :(得分:0)
在WinForms中,您应该能够设置
Me.dataEvidence.SelectedRows
要选择的行的属性。
答案 2 :(得分:0)
在Visual Studio 2012 (vb.NET Framework 4.50 )中,您可以将焦点设置在DataGridView控件的任何所需单元格上。
试试这个:
Sub Whatever()
' all above code
DataGridView1.Focus()
DataGridView1.CurrentCell = DataGridView1.Rows(x).Cells(y) 'x is your desired row number, y is your desired column number
' all below code
End Sub
好的,这对我有用。我希望它对你也有用。