Public Class Form1
Dim dt As DataTable
Dim bs As BindingSource
Function generateDt() As DataTable
Dim dt As New DataTable
dt.Columns.Add("sno", GetType(Integer))
dt.Columns.Add("name", GetType(String))
dt.Rows.Add(New Object() {1, "Jack"})
dt.Rows.Add(New Object() {2, "Jill"})
Return dt
End Function
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
bs = New BindingSource
dt = generateDt()
bs.DataSource = dt
DataGridView1.DataSource = bs
End Sub
Private Sub DataGridView1_SelectionChanged(sender As Object, e As System.EventArgs) Handles DataGridView1.SelectionChanged
If bs.Current Is Nothing Then
Label1.Text = ""
TextBox1.Clear()
Return
End If
Label1.Text = bs.Current("sno")
TextBox1.Text = bs.Current("name")
End Sub
End Class
you can try out the code by draging one datagridview(datagridview1), a label(label1) and one textbox (textbox1) to your form(form1) then copy and paste the code to form1.vb code page.
Hope this helps