I am trying to have a situation where if a user clicks on a certain row in a datagridview control the value in the datagridview row will be shown for a a certain column. Column 1 in my datagridview control has Names in it so I want if a user clicks row 0 the name in row 0 will be shown and if a user clicks row 1 the name in row 1 will be shown etc. this is the code I have so far. ! tried line 2 2 in my code but it shows whatever cell i click and sometimes its not an id . help

Private Sub DataGridView1_Click(sender As Object, e As System.EventArgs) Handles DataGridView1.Click
    txttID.Text = DataGridView1.CurrentCell.Value
    ' txttSurname.Text = DataGridView1.Columns(1)
    txttSurname.Text = DataGridView1.Rows(DataGridView1.).Cells(1).Value
End Sub

Edited 4 Years Ago by pyTony: fencing ~~~ vb code tags added

Try :

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    Dim i As Integer = DataGridView1.CurrentRow.Index
    txttID.Text = DataGridView1.Item(0, i).Value
    txttSurname.Text = DataGridView1.Item(1, i).Value
End Sub

Edited 4 Years Ago by Jx_Man: code tag

This question has already been answered. Start a new discussion instead.