我试图遍历两个列表框并将所有项目添加到一个列表中。 到目前为止,这是我的代码,但我似乎无法将第二个列表框集成到其中。
Dim List As List(Of String) = New List(Of String)
For Each LB1 As String In Listbox1.Items
List.Add(vbTab + vbTab + "ent = maps\mp\_utility::createOneshotEffect(" + """" + LB1.ToString() + """" + ");" + vbCrLf +
vbTab + vbTab + "ent.v[ " + """" + "origin" + """" + " ] = ( " + LB2.ToString() + " );"
Next
答案 0 :(得分:0)
只要LB1和LB2都包含相同数量的项目并且两者的排序相同,您就可以使用索引循环(而不是foreach循环):
Dim List As List(Of String) = New List(Of String)
For x as integer = 0 to Listbox1.Items.count - 1
List.Add(vbTab + vbTab + "ent = maps\mp\_utility::createOneshotEffect(""" + _
ListBox1.Items(x).ToString() + """);" + vbCrLf + _
vbTab + vbTab + "ent.v[ ""origin"" ] = ( " + _
ListBox2.Items(x).ToString() + " );" _
)
Next