简体   繁体   English

如何将项目从列表框添加到另一个列表框?

[英]How to add items from a listbox to another listbox?

I know from textbox to listbox you can use something like: 我知道从文本框到列表框,您可以使用类似以下内容的东西:

listBox1.Items.Add(textBox1.Text)

But how would this work between two listboxes? 但是,这在两个列表框之间如何工作? Thanks. 谢谢。

Assuming the SelectionMode is set to One , and you want to Copy the selected item: 假设SelectionMode设置为One ,并且您要复制所选项目:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If ListBox1.SelectedIndex <> -1 Then
        ListBox2.Items.Add(ListBox1.SelectedItem)
    End If
End Sub

If you want to Move the selected item, then: 如果要移动选定的项目,则:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If ListBox1.SelectedIndex <> -1 Then
        ListBox2.Items.Add(ListBox1.SelectedItem)
        ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
    End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM