datagridview to textbox binding data
When the program is executed, the datagridview populate data and also the textboxes(example StockNumber,Description) and when i typed words in the search textbox ,the datagridview filters the matching words.When I clicked the item in the datagridview the textboxes does not changed it didnt show the information...
what the solution for my problem..i need to display the information in the textboxes when i clicked the item in the datagridview..
Private Sub txtreg_delsrch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtreg_delsrch.TextChanged
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\sony\Documents\Visual Studio 2008\Projects\Inventory\ItemInventory.mdb")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT StockNo,Item,Description,Reference,Quantity,Unit F开发者_高级运维ROM Supplies_Regular WHERE Description Like '%" & txtreg_delsrch.Text & "%'", con)
con.Open()
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "MyTable")
Supplies_RegularDataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
End Sub
Perhaps you could use BindingSource
:
Dim binding = New BindingSource()
With { .DataSource = myDataSet.Tables("MyTable") }
Supplies_RegularDataGridView1.DataSource = binding
StockNumber_textBox1.DataBindings.Add("Text", binding, "StockNo")
Last line simply binds your object's StockNo
property to TextBox.Text
.
You could do something like this in the Grid CellClick
event.
Dim row As Integer = e.RowIndex
Dim col As Integer = e.ColumnIndex
textbox.Text = grid.Item(col, row).value
精彩评论