在后面的代码中,您必须使用组合框的“SelectedIndexChanged”事件。在该函数中,您可以将文本框文本更改为您喜欢的任何内容。例如,如果我们有一个名为 cmbTest 的组合框和一个名为 txtTest 的文本框:
Private Sub cmbTest_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbTest.SelectedIndexChanged
txtTest.Text = "whatever text you want"
End Sub
您可以使用 select 语句根据组合框来决定要使用的文本,例如:
Private Sub cmbTest_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbTest.SelectedIndexChanged
Select Case cmbTest.SelectedIndex
Case 1
txtTest.Text = "The Selected index is 1"
Case 2
txtTest.Text = "The Selected index is 2"
Case 3
txtTest.Text = "The Selected index is 3"
End Select
End Sub
您可以按照这些方式来访问 access 数据库中的数据(显然,您需要将 sql 语句替换为您在 access db 中拥有的任何表/列):
Dim dt As New DataTable
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PATH_TO_MDB_FILE\db1.mdb;")
Try
cn.Open()
Dim Str As String = "SELECT * FROM yourTableName WHERE columnName = '" & ComboBox1.SelectedValue.ToString & "'" ' Or whatever SQL statement you want
Dim cmd As New OleDbCommand(Str, cn)
dt.Load(cmd.ExecuteReader())
Catch
'handle error
End Try
cn.Close()
然后您可以使用数据表访问要放入文本框的文本,例如:
txtTest.Text = dt.Rows(0).Item("ColumnName").ToString()
我希望这会有所帮助,并且我明白你想要什么。