vb.net VB:将所有文本从一个列表框传输到另一个列表框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22339604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:02:40  来源:igfitidea点击:

VB: Transfering all text from one listbox to another

vb.net

提问by user3387807

Thanks for reading guys first of all. Secondly I'd like button1 to transfer all text from listbox1 to listbox2. So when button1 is clicked, all items in listbox1 transfers to listbox2. Here is what I have, thanks again:

首先感谢大家阅读。其次,我希望 button1 将所有文本从 listbox1 传输到 listbox2。因此,当单击 button1 时,listbox1 中的所有项目都会转移到 listbox2。这是我所拥有的,再次感谢:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button4.Click

   ListBox2.Items.Add(ListBox1.SelectedItems)

End Sub

Using VB2012

使用VB2012

回答by Neolisk

To copy all items from one listbox to another (ListBox1 -> ListBox2):

要将所有项目从一个列表框复制到另一个列表框 (ListBox1 -> ListBox2):

ListBox2.Items.AddRange(ListBox1.Items)

回答by slek

try this:

尝试这个:

    ListBox2.Items.Clear()  //This is to avoid duplication if button was clicked more than once

     For i = 0 To ListBox1.Items.Count - 1
        ListBox2.Items.Add(ListBox1.Items(i).ToString)
    Next

回答by Edper

You traverse on the 1st Listboxselected items and add each item in your 2nd ListBox, like

您遍历第一个Listbox选定的项目并在第二个中添加每个项目ListBox,例如

For Each Item As String In ListBox1.SelectedItems
  ListBox2.Items.Add(Item)
Next