当程序执行时,datagridview会填充数据以及文本框(例如StockNumber,Description),当我在搜索文本框中输入单词时,datagridview会过滤匹配的单词。当我在datagridview中单击该项时,文本框没有改变它没有显示信息...
我的问题的解决方案..我需要在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 FROM 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
答案 0 :(得分:2)
也许您可以使用BindingSource
:
Dim binding = New BindingSource()
With { .DataSource = myDataSet.Tables("MyTable") }
Supplies_RegularDataGridView1.DataSource = binding
StockNumber_textBox1.DataBindings.Add("Text", binding, "StockNo")
最后一行只是将对象的StockNo
属性绑定到TextBox.Text
。
答案 1 :(得分:0)
您可以在Grid CellClick
事件中执行类似的操作。
Dim row As Integer = e.RowIndex
Dim col As Integer = e.ColumnIndex
textbox.Text = grid.Item(col, row).value