正如标题所示,一旦我从lstordpizza中选择一个项目,lstordserving和lstordqty中的相应项目将从图像中显示的组合框中显示出来。任何帮助,将不胜感激。 :)
编辑:很抱歉我的帖子信息不足,我无法想办法。当我选择' Hawaiian Supreme'时,相应的项目是' Family'应出现在组合框中以及数量'#'
答案 0 :(得分:0)
首先,当您使用for循环打开表单时,需要在组合框中加载列表框项。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each item As String In ServinSizeLB.Items
ServinSizeCB.Items.Add(item)
Next
For Each item As Integer In PizzaQtyLB.Items
PizzaQtyCB.Items.Add(item)
Next
End Sub
然后将PickIndexChanged事件添加到披萨列表框中 因此,只要您在列表框中选择披萨,就可以选择组合框中其他列表框的值 但首先您需要检查列表框中是否已选择值 否则,当您选择不同的披萨时,选择就会消失 “也许我已经知道了它的大小,但我确实改变了我对我想要的披萨的想法”
Private Sub PizzaLB_SelectedIndexChanged(sender As Object, e As EventArgs) Handles PizzaLB.SelectedIndexChanged
If ServinSizeLB.SelectedItem = Nothing Then
ServinSizeCB.SelectedIndex = 0
End If
If PizzaQtyLB.SelectedItem = Nothing Then
PizzaQtyCB.SelectedIndex = 0
End If
End Sub
你不应该忘记第一项是在0号位置
我不知道您是否希望他们从列表框或组合框中选择服务大小或披萨数量...
但这里也是代码,如果它是列表框。
因此,即使是服务大小列表框,也要制作一个SelectedIndexChanged,一个用于披萨数量列表框
Becaus项目与列表框中的顺序相同,组合框将组合框选定项目与列表框选定项目链接。
Private Sub ServinSizeLB_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ServinSizeLB.SelectedIndexChanged
ServinSizeCB.SelectedIndex = ServinSizeLB.SelectedIndex
End Sub
Private Sub PizzaQtyLB_SelectedIndexChanged(sender As Object, e As EventArgs) Handles PizzaQtyLB.SelectedIndexChanged
PizzaQtyCB.SelectedIndex = PizzaQtyLB.SelectedIndex
End Sub
如果在组合框中选择一个值,则与列表框相同。
Private Sub ServinSizeCB_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ServinSizeCB.SelectedIndexChanged
ServinSizeLB.SelectedIndex = ServinSizeCB.SelectedIndex
End Sub
Private Sub PizzaQtyCB_SelectedIndexChanged(sender As Object, e As EventArgs) Handles PizzaQtyCB.SelectedIndexChanged
PizzaQtyLB.SelectedIndex = PizzaQtyCB.SelectedIndex
End Sub