[英]How to move cursor to the next row in datagridview
我有一個Windows窗體,其中包含2個datagridviews和它們之間的一個按鈕,用於傳輸數據。 在按鈕成功傳輸數據后,我無法弄清楚如何將所選行的光標移動到下一行。
if (dataGridView1.CurrentRow != null)
dataGridView1.CurrentCell =
dataGridView1
.Rows[Math.Min(dataGridView1.CurrentRow.Index + 1, dataGridView1.Rows.Count - 1)]
.Cells[dataGridView1.CurrentCell.ColumnIndex];
if (e.KeyChar == (char)13)
{
int col = grdIdeal.CurrentCell.ColumnIndex;
int row = grdIdeal.CurrentCell.RowIndex;
int nRows = grdIdeal.Rows.Count - 1;
int nCol = grdIdeal.Columns.Count - 1;
if (nCol == col && nRows == row)
grdIdeal.CurrentCell = grdIdeal[0, 0];
else if (nRows == row)
grdIdeal.CurrentCell = grdIdeal[col + 1, 0];
else
grdIdeal.CurrentCell = grdIdeal[col, row + 1];
e.Handled = true;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.