後面的代碼中,你將不得不使用組合框的「的SelectedIndexChanged」事件。在該功能中,您可以將文本框文本更改爲任何您喜歡的內容。例如,如果我們有一個名爲cmbTest COMBOX並呼籲txtTest文本框:
Private Sub cmbTest_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbTest.SelectedIndexChanged
txtTest.Text = "whatever text you want"
End Sub
你可以使用select statment決定使用基於組合框例如什麼文本:
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語句):
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()
然後,您可以使用數據表來訪問文本放入文本框e.g:
txtTest.Text = dt.Rows(0).Item("ColumnName").ToString()
我希望幫助,而且我明白你想要什麼。