[英]VB.net 2013 Display Database Record According Listbox Selection
I want to display Database Record into textbox according to my listbox selection. 我想根据我的列表框选择将“数据库记录”显示在文本框中。
I have showed database record by NAME into listbox like this. 我已经将NAME的数据库记录显示在这样的列表框中。
Private Sub getPurchases()
cmd = New MySqlCommand("SELECT * FROM detail_buy ORDER BY id DESC", conn)
da = New MySqlDataAdapter
da.SelectCommand = cmd
dt.Clear()
da.Fill(dt)
LBPmb.DataSource = dt
LBPmb.ValueMember = "name"
End Sub
Now I want to show the other value like ID, Price, Total, etc,etc into each textboxes when I click the 'names' on listbox. 现在,当我单击列表框上的“名称”时,我想在每个文本框中显示其他值,如ID,价格,总计等。 Is that possible?
那可能吗?
You should bind the same DataTable
to the TextBoxes
as well, eg 您也应该将相同的
DataTable
绑定到TextBoxes
,例如
With myListBox
.DisplayMember = "ColumnToDisplay1"
.ValueMember = "PKColumn"
.DataSource = myDataTable
End With
myTextBox.DataBindings.Add("Text", myDataTable, "ColumnToDisplay2")
The TextBox
will then be automatically populated when you make a selection in the ListBox
. 当您在
ListBox
进行选择时, TextBox
将自动填充。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.