【发布时间】:2017-05-02 06:44:14
【问题描述】:
给定这样的课程
Public Class ItemPanel
Inherits Panel
Public Name as string
Public Quantity As Integer
End Class
还有这样的列表
Public li_ip As New List(Of ItemPanel)
我有一个子会帮我在单击按钮时将ItemPanel添加到li_ip列表中,每个单击的按钮也会将其文本添加到li_item中,因此当一个按钮单击两次时,只有第一次会将ItemPanel添加到li_ip,第二次单击只会改变 ItemPanel 中的数量
Private Sub RefreshOrdered(sender As Object)
If Not li_item.Contains(sender.Text) Then
Dim pn As ItemPanel
With pn
.Name = sender.Text
.Quantity = 1
End With
li_ip.Add(pn)
Else
'Here I want to change the quantity in ItemPanel depend on the sender.Text
End If
End Sub
那么我怎样才能得到我想要的结果呢?后面应该写什么?
【问题讨论】:
-
要从列表中获取项目,此答案将有所帮助:stackoverflow.com/a/200165/5152045
-
在我看来你想要一个
Dictionary(Of String, Integer)。你检查过List以外的容器吗?