Arrays 用两个数组中的数据填充列表框
我需要以下方面的帮助: 在Visual Studio中将两个数组中的数据填充到列表框中 第一个数组保存日期信息(例如2020年11月2日),第二个数组保存折扣信息(例如25%折扣) 因此,在Arrays 用两个数组中的数据填充列表框,arrays,vb.net,Arrays,Vb.net,我需要以下方面的帮助: 在Visual Studio中将两个数组中的数据填充到列表框中 第一个数组保存日期信息(例如2020年11月2日),第二个数组保存折扣信息(例如25%折扣) 因此,在表单加载事件中,两个数组中保存的数据应填充到列表框中,如下所示: 11/2/2020=25%折扣 等等。如蒙协助,将不胜感激 Dim strDates() As String = {"11/2/2020", "11/12/2020", "11/22/2
表单加载
事件中,两个数组中保存的数据应填充到列表框中,如下所示:
11/2/2020=25%折扣
等等。如蒙协助,将不胜感激
Dim strDates() As String = {"11/2/2020", "11/12/2020", "11/22/2020", "11/30/2020"}
Dim strDiscount() As String = {"25", "10", "35", "21"}
Dim intPos As Integer = 0
For Each strDate As String In strDates
strDate += " = " & strDiscount(intPos) & "% Discount"
ListBox1.Items.Add(strDate)
intPos += 1
Next
导致每个项目获得:
11/2/2020 = 25% Discount
11/12/2020 = 10% Discount
11/22/2020 = 35% Discount
11/30/2020 = 21% Discount
有用链接:
您也可以将这些数组组合在一起,并将其设置为列表框的.DataSource
:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dates() As String = {"11/2/2020", "11/3/2020", "11/4/2020", "11/5/2020"}
Dim discounts() As Integer = {25, 10, 50, 15}
Dim entries = dates.Zip(discounts, Function(dt, disc) dt & " = " & disc & "% Discount")
ListBox1.DataSource = entries.ToList
End Sub