datagridview value to textbox

  • Thread starter Thread starter no[one]
  • Start date Start date
N

no[one]

Guest
guys pls help me, i want to put a value in my textbox from a datagridview here is my full code

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
load()

Dim btnmore As New DataGridViewButtonColumn()
DataGridView1.Columns().Add(btnmore)
btnmore.HeaderText = "Action"
btnmore.Text = "More Details"
btnmore.Name = "btnmore"
btnmore.UseColumnTextForButtonValue = True

End Sub
Sub load()
Dim query As String = "select * from info"
Dim adpt As New MySqlDataAdapter(query, con)
Dim ds As New DataSet()
adpt.Fill(ds, "Emp")
DataGridView1.DataSource = ds.Tables(0)
con.Close()
End Sub

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim adapater As MySqlDataAdapter
Dim ds As New DataSet
Try
con.Open()
adapater = New MySqlDataAdapter("Select * from info where name Like '%" & TextBox1.Text & "%' OR
address like '" & TextBox1.Text & "%' ", con)
adapater.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
con.Close()
Catch ex As Exception
End Try
End Sub

Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim row As DataGridViewRow = DataGridView1.CurrentRow
TextBox2.Text = row.Cells(0).Value.ToString()
End Sub


what i want to do is to put the ID in my textbox2 but when i search from my textboxsearch and select a row in my datagridview, the text in my button will appear in my textbox2,

1362849.jpg

Continue reading...
 
Back
Top