[英]How to select and set focus a datagrid row programmatically using MVVM design pattern in WPF
[英]How to programmatically set focus on a row in a WinForms DataGrid when selecting it?
由于这是旧的System.Windows.Forms.DataGrid ,因此行选择方法与 DataGridView 略有不同。
您可以使用Select()方法 select 一行。
这不会更改当前行。 要使行成为当前行,您可以使用CurrentRowIndex属性。
结合起来,这两个移动选择并设置当前行。
// Selects and highlights the Row at index 1
dataGrid.Select(1);
// Make the Row at index 1 the Current
dataGrid.CurrentRowIndex = 1;
DataGridView 中的类似内容:
(可用于实现此结果的方法之一)
// Move the focus and selects the Row at index 1
dataGridView.Rows[1].Selected = true;
// Make the Row at index 1 the Current setting the CurrentCell property
dataGridView.CurrentCell = dgvTest.Rows[1].Cells[0];
尝试这个:
dataGridView1.FirstDisplayedScrollingRowIndex =
dataGridView1.Rows[dataGridView1.Rows.Count - 2].Index;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.