Home > VB.NET > Move to Next DataGridView Row via Code

Move to Next DataGridView Row via Code


Dim _rowIndex = grdDataLines.SelectedRows(0).Index + 1
If _rowIndex <= grdDataLines.Rows.Count - 1 Then

Dim nextRow As DataGridViewRow = grdDataLines.Rows(_rowIndex)

' Move the Glyph arrow to the next row
grdDataLines.CurrentCell = nextRow.Cells(0)
grdDataLines.Rows(_rowIndex).Selected = True

End If

Categories: VB.NET Tags:
  1. tiny
    March 8, 2013 at 5:32 am

    Really a big help thanks!!!

  2. ahmadKhalifa
    December 8, 2013 at 6:52 am

    grdDataLines.Rows.Add()
    grdDataLines.Rows(grdDataLines.CurrentRow.Index).Selected = True
    ‘—————————————————————
    add the above lines before that code

    • October 17, 2016 at 5:26 am

      Thanks. I want the same code to work, while move to next button is click it will appear on the textbox.

  3. January 5, 2014 at 1:40 am

    thanks
    sir 🙂

  4. August 14, 2014 at 5:17 am

    private void tsMoveNext_Click(object sender, EventArgs e)
    {
    //make sure datagrid is not empty
    if (dataGridView1.RowCount >=1)
    {
    int _rowIndex = dataGridView1.SelectedRows[0].Index + 1;
    //make sure the current row is not the last row
    if (_rowIndex <= dataGridView1.Rows.Count -1)
    {
    DataGridViewRow nextRow = dataGridView1.Rows[_rowIndex];
    dataGridView1.CurrentCell = nextRow.Cells[0];
    dataGridView1.Rows[_rowIndex].Selected = true;
    }
    }
    }

    Make sure that datagrid is not empty and the current row is not the last row.
    Sorry for posting this in c#.
    Regards …

  5. October 17, 2016 at 5:20 am

    Big thanks. I need the code that will be prompt to textbox after move to next button is click

  1. No trackbacks yet.

Leave a comment