我的表格上有一个组合框。这与一个表格相关联,该表格包含员工姓名和该人员的员工参考。
Combobox显示所有员工姓名和选择应该创建 staffRef 的值,我希望能够选择名称,并且 StaffRef 被填充到文本框。
到目前为止,我只能得到 StaffRef 这个词。
这是我的代码,希望你能帮忙!
Private Sub frmAddCar_Load(sender As System.Object, e As System.EventArgs)
Handles MyBase.Load
'TODO: This line of code loads data from the 'namesstolenpool' table and drops
it into the combobox(Driver_Name).
Dim table As DataTable
table = BusinessData.VerifierLogic.Load("namesstolenpool",
New Dictionary(Of String, Object))
Driver_name.DataSource = table
Driver_name.DisplayMember = "displayname"
Driver_name.ValueMember = "staffref"
End Sub
'This should display the "value" of the combobox in the textbox.
Private Sub Driver_name_SelectedIndexChanged(sender As System.Object
, e As System.EventArgs) Handles Driver_name.SelectedIndexChanged
TextBox1.Text = Driver_name.ValueMember
End Sub
End Class
答案 0 :(得分:0)
尝试这样
Private Sub Driver_name_SelectedIndexChanged(sender As System.Object
, e As System.EventArgs) Handles Driver_name.SelectedIndexChanged
TextBox1.Text = Driver_name.SelectedItem("staffref")
End Sub