這是錯誤的結合方式....這是你如何做到這一點: 我有一個簡單的形式與組合框和文本框 和2列「代碼」和「說明」的DataTable模擬你的情況
這裏的代碼(如果你請,不要忘記我的答案標記爲右):當你進入「CODE3」,打
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Me.KeyPreview = True'To Enable the Key events : KeyDown, KeyPress and KeyUp
Dim dt As New DataTable("T")
dt.Columns.Add(New DataColumn("Code"))
dt.Columns.Add(New DataColumn("Description"))
For i = 1 To 10
Dim r As DataRow = dt.NewRow
r("Code") = "Code" + CStr(i)
r("Description") = "Desc" + CStr(i)
dt.Rows.Add(r)
Next
With ComboBox1
.ValueMember = "Code" ' This is case sensitive
.DisplayMember = "Description" ' This is case sensitive
.DataSource = dt
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click
SetComoboValue()
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then SetComoboValue()
End Sub
Private Sub SetComoboValue()
Try
If Not String.IsNullOrEmpty(TextBox1.Text) Then
ComboBox1.SelectedValue = TextBox1.Text
End If
Catch ex As Exception
MsgBox("Ooops, Invalid code !!!")
End Try
End Sub
End Class
所以輸入或點擊在TextBox1中,在ComboBox1將顯示「Desc3」
oooooooooooooooooooo感謝這真的幫助了很多問題只有一個,爲什麼我的組合框似乎打亂提供商綁定值是多少?是正常的嗎?那唯一thanx的答案 – 2012-02-19 20:40:39
我不知道該怎麼查詢(或一些別的東西),在你的供應商的數據表,可以說,它的「選擇代碼,描述從商」,使其排序只是讓「選擇代碼,描述從商ORDER BY說明」 – 2012-02-19 20:54:07
好,我直接從供應商表綁定到組合框不知道這是爲什麼它似乎是混亂,但也不要緊,現在:d感謝 – 2012-02-19 21:18:40