[英]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.