Visual Basic 2008 Combobox 项目历史轨迹(winforms)
Visual Basic 2008 Combobox item history track (winforms)
有什么方法可以让您知道组合框中最后一个选择之前的上一个选择吗?
例如,假设一个组合框有 3 个项目:1、2、3
选择项目2和3(从下拉列表组合列表中)时,我想知道选择项目3后的上一项是项目2。
有人可以帮帮我吗?我将使用它来 decrease/increase 购物篮中的数量。当用户选择一种产品时,数量必须自动减少,但如果用户更改为另一种产品,则必须再次增加前一种产品的数量以避免一致性问题。
这样的事情可能会有所帮助,我正在使用堆栈,因此您可以看到最后添加的条目。编辑:在初始化时,我为组合框设置了一个索引标记,这样您就可以将其添加到数组中该组合框的堆栈中。编辑 编辑:我已经添加,因此它会搜索所有组合框控件的表单并添加它们,因此您不必自己手动添加标签或组合框。
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
有什么方法可以让您知道组合框中最后一个选择之前的上一个选择吗?
例如,假设一个组合框有 3 个项目:1、2、3 选择项目2和3(从下拉列表组合列表中)时,我想知道选择项目3后的上一项是项目2。
有人可以帮帮我吗?我将使用它来 decrease/increase 购物篮中的数量。当用户选择一种产品时,数量必须自动减少,但如果用户更改为另一种产品,则必须再次增加前一种产品的数量以避免一致性问题。
这样的事情可能会有所帮助,我正在使用堆栈,因此您可以看到最后添加的条目。编辑:在初始化时,我为组合框设置了一个索引标记,这样您就可以将其添加到数组中该组合框的堆栈中。编辑 编辑:我已经添加,因此它会搜索所有组合框控件的表单并添加它们,因此您不必自己手动添加标签或组合框。
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