0
早些時候,我能夠填充組合框取決於另一個組合框選擇,然後我繼續編寫代碼,然後我再回來測試它再次,它不再填充該列表,它與另一個列表一起使用,但其中一個不包含。所以它填充飲料,但不是主要的。我不確定發生了什麼事情,這一切對我來說似乎都沒有問題。當我嘗試填充組合框時,它不填充
Public Shared cmbCatDrinks As String = "Drinks"
Public Shared cmbCatMain As String = "Main"
Public Shared cmbCatBlank As String = ""
Public Shared cmbItemBlank As String = ""
Private Sub frmRestaurantOrd_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cmbCat.Items.Add(cmbCatBlank)
cmbCat.Items.Add(cmbCatDrinks)
cmbCat.Items.Add(cmbCatMain)
End Sub
Private Sub cmbCat_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbCat.SelectedIndexChanged
If cmbCat.SelectedItem = "Drinks" Then
cmbItem.Items.Add("Water")
cmbItem.Items.Add("Orange Juice")
cmbItem.Items.Add("Coca Cola")
cmbItem.Items.Add("Beer")
cmbSize.Items.Clear()
ElseIf cmbCat.SelectedItem = "Main" Then
cmbItem.Items.Add("Cheese and Tomato")
cmbItem.Items.Add("Ham and Pineapple")
cmbItem.Items.Add("Vegetarian")
cmbItem.Items.Add("Meat Feast")
cmbItem.Items.Add("Seafood")
cmbSize.Items.Add("Small")
cmbSize.Items.Add("Medium")
cmbSize.Items.Add("Large")
cmbItem.Items.Clear()
Else cmbCat.SelectedItem = cmbCatBlank
cmbItem.Items.Clear()
End If
End Sub
謝謝,我沒有記時。我也試圖讓它清除組合框中的當前選定項目,我將其設置爲當我在組合框中選擇空白選擇時清除其他組合框,但它不清除如果這有意義,那麼選擇了哪些文本? – Ollie4735
@ Ollie4735設置'cmbItem.DropDownStyle = ComboBoxStyle.DropDownList' – LarsTech
我發現另一種方法來做我所需要的是cmbItem.ResetText() – Ollie4735