how to grab the values from datagridview selected row to textbox

Submitted by velovely on
  1. Private Sub frmVisitor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3. dbConnection.ConnectionString = _
  4.         "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =SNGPLDbase.mdb"
  5. dbConnection.Open()
  6. daVisitor = New OleDb.OleDbDataAdapter("Select * From Visitor", dbConnection)
  7. cmdbVisitor = New OleDb.OleDbCommandBuilder(daVisitor)
  8. daVisitor.Fill(dtVisitor) 'Because the DataTable doesn't hold a connection to the data source, you don't need to close it when you're finished.
  9.  
  10.         Dim ds As New DataSet
  11.  
  12.         Dim drNewRow As DataRow = dtVisitor.NewRow()
  13.  
  14.         dtVisitor.Columns(2).DataType = GetType(String)
  15.  
  16.         dtVisitor.Columns(0).AutoIncrement = True
  17.         dtVisitor.Columns(0).AutoIncrementSeed = 10
  18.         dtVisitor.Columns(0).AutoIncrementStep = 10
  19.  
  20.  
  21.         DataGridView1.Refresh()
  22.         DataGridView1.DataSource = dtVisitor.DefaultView
  23.         DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
  24.  
  25.         cboVisitorCode.DataSource = dtVisitor.DefaultView
  26.         cboVisitorCode.DisplayMember = "VisitorCode"
  27.         AddHandler cboVisitorCode.SelectedIndexChanged, AddressOf cboVisitorCode_SelectedIndexChanged
  28.  
  29.  
  30.     End Sub
  31.  
  32. Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  33.  
  34.         Me.txtVisitorName.Text = ""
  35.         Me.txtVehicleNo.Text = ""
  36.  
  37. End Sub
  38.  
  39.     Private Sub cboVisitorCode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboVisitorCode.SelectedIndexChanged
  40.        
  41. 'Modified code here for selected row feilds to textbox
  42. 'Also for direct select row from datagridview
  43.  
  44. 'for example
  45.      '   Me.txtVisitorName.Text= "Abc"
  46.      '   Me.txtVehicleNo.Text = "xyz250"
  47.  
  48.  
  49.  
  50.     End Sub