是否有任何方法可以让您在组合框中的最后一次选择之前知道之前的选择?
例如,假设一个组合框有3个项目:1,2,3 当选择项目2然后3(从下拉组合框列表)时,我想知道选择项目3之后的前一项目是项目2.
是的,有人能帮帮我吗?我将使用它来减少/增加购物篮中的数量。当用户选择产品时,数量必须自动减少,但如果用户更改为另一产品,则必须再次增加前一个产品的数量,以避免一致性问题。答案 0 :(得分:1)
这样的事情可能有所帮助,我使用堆栈,因此您可以看到最后添加的条目。编辑:在init上,我将一个索引标记设置为组合框,以便您可以添加到数组中该组合框的堆栈。编辑编辑:我已添加,所以它搜索所有组合框控件的表单并添加它们,因此您不必自己手动添加标签或组合框。
Dim lastSelectedArr() As Stack(Of String)
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Dim index As Integer = 1
Dim combos As New List(Of ComboBox)
For Each c As Control In Me.Controls
If (c.GetType() = GetType(ComboBox)) Then
Dim combo As ComboBox = CType(c, ComboBox)
combo.Tag = index
combos.Add(CType(c, ComboBox))
index += 1
End If
Next
ReDim lastSelectedArr(combos.Count - 1)
For i As Integer = 0 To lastSelectedArr.Length - 1
lastSelectedArr(i) = New Stack(Of String)
Next
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged
Dim cb As ComboBox = CType(sender, ComboBox)
Dim CBID As Integer = CInt(cb.Tag) - 1
lastSelectedArr(CBID).Push(cb.SelectedItem)
Dim retStr As String = String.Empty
For Each value As String In lastSelectedArr(CBID)
retStr = retStr + value + ","
Next
MessageBox.Show(retStr)
End Sub