很抱歉,如果之前已经回答了这个问题,但是我搜索了网站,找不到任何能回答我问题的内容。
我可以在列表框之间移动所选项目但是如何从一个列表框中移动所有项目并将它们添加到另一个列表框中?如果可能的话,我想将它们附加到底部,而不是替换其他列表框中的项目。
我用来移动特定项目的编码是
Dim selectedItems = (From i In ListBox1.SelectedItems).ToArray()
For Each selectedItem In selectedItems
ListBox2.Items.Add(selectedItem)
ListBox1.Items.Remove(selectedItem)
Next
由于某些原因我无法回答我自己的问题,但很多人感谢Heinzi,对于其他有相同问题的人,以下编码应该对你有帮助。
Dim selectedItems =(来自i在ListBox1.Items中).ToArray()
For Each selectedItem In selectedItems
ListBox2.Items.Add(selectedItem)
ListBox1.Items.Remove(selectedItem)
Next
答案 0 :(得分:2)
您可以使用相同的代码,但迭代通过ListBox1.Items而不是ListBox1.SelectedItems:
Dim itemsToMove = ListBox1.Items.ToArray() ' to make a copy of the list of items
For Each item In itemsToMove
ListBox2.Items.Add(item)
ListBox1.Items.Remove(item)
Next
答案 1 :(得分:0)
试试这个来移动所有项目 - 工作 100%
Sub GetCompanyInfo()
Dim hReq As Object, json As Object, strUrl As String
Dim i As Long, var, ws As Worksheet, response As String
Set ws = ActiveSheet
strUrl = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" & _
ws.cells(1, 2).Value & "&apikey=x"
Set hReq = CreateObject("MSXML2.XMLHTTP")
With hReq
.Open "GET", strUrl, False: .send
response = .responseText
End With
Set json = JsonConverter.ParseJSON(response)("Time Series (Daily)")
i = 2
For Each var In json
ws.cells(i, 1).Value = var
ws.cells(i, 2).Value = json(var)("1. open")
i = i + 1
Next var
MsgBox "Ready..."
End Sub
The above code works with the assumption that you have the module `JsonConverter` accessible to the project.