I am trying to select a row in my datagrid.
There are two columns only.
The row displays into two text boxes. I am trying to figure out how to select the next row in my datagrid. I have tried looking at your examples but I am still having trouble.
Using visual basic. See my code below.

Private Sub btnDisplayListing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayListing.Click

Dim names() As String = IO.File.ReadAllLines("name.txt")
Dim query1 = From line In names
Let data = line.Split(","c)
Let name = data(0)
Let phonenum = data(1)
Select name, phonenum
dgvOutput.DataSource = query1.ToList
dgvOutput.CurrentCell = Nothing

dgvOutput.Columns("name").HeaderText = "Name"
dgvOutput.Columns("phonenum").HeaderText = "Phone Number"
dgvOutput.Focus() 'displays first name on list, must do a loop here.

txtName.Text = dgvOutput.CurrentRow.Cells(0).Value.ToString '// column 1.
txtPhoneNumber.Text = dgvOutput.CurrentRow.Cells(1).Value.ToString '// column 2
Dim i As Integer

dgvOutput.Rows(i).Selected = True
dgvOutput.CurrentCell = dgvOutput.Rows(i).Cells(0)

End Sub

When you post code, please surround it with code tags. The easiest way is to paste the code, make sure it is all selected, then click the CODE tool at the top of the edit box.

The following code iterates over all rows in the datagrid and prints the values of the first two cells in each row.

For i As Integer = 0 To DataGridView1.RowCount - 1
    Debug.WriteLine(DataGridView1.Rows(i).Cells(0).Value & " " & DataGridView1.Rows(i).Cells(1).Value)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.