简体   繁体   English

如何将光标移动到datagridview中的下一行

[英]How to move cursor to the next row in datagridview

I have a Windows Form that contains 2 datagridviews and a button between them to transfer the data. 我有一个Windows窗体,其中包含2个datagridviews和它们之间的一个按钮,用于传输数据。 I cannot figure out how should i move the cursor of selected row to the next row after the button has successfully transfer the data. 在按钮成功传输数据后,我无法弄清楚如何将所选行的光标移动到下一行。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM