注册 登录
编程论坛 VB.NET论坛

vb.net中怎样把listbox1中选中的内容增加到listbox2中

lhj56459897 发布于 2018-09-13 20:35, 5443 次点击
请教各位:中怎样把listbox1中选中的内容增加到listbox2中
6 回复
#2
moou2018-09-17 12:31
程序代码:

        '遍历listbox1所有项
        For i = 0 To ListBox1.Items.Count - 1
            '清空listbox2
            ListBox2.Items.Clear()
            '向listbox2添加对应的listbox1 的内容
            ListBox2.Items.Add(ListBox1.Items(i).ToString)
        Next
#3
moou2018-09-17 12:31
回复 2楼 moou
如果只是添加 不用清空listbox2
#4
moou2018-09-17 13:10
程序代码:

        For Each strCopy As String In listbox1.Items
            listbox2.Items.Add(strCopy)
        Next
#5
lhj564598972018-09-17 23:03
Dim i, j As Integer
        Dim zjbd As Boolean
        zjbd = False
        If ListBox1.SelectedIndex = -1 Then Exit Sub
        For i = 0 To ListBox1.Items.Count - 1
            If ListBox1.GetSelected(i) = True Then
                For j = 0 To ListBox2.Items.Count - 1
                    If ListBox1.Items(i) = ListBox2.Items(j) Then
                        zjbd = True
                    End If
                Next
                If zjbd = False Then ListBox2.Items.Add(ListBox1.Items(i))
                zjbd = False
            End If
        Next
#6
moou2018-09-19 16:46
这么长你不烦啊 for each 三行搞定
#7
ppppooiiuu2018-09-19 19:09
1