| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5309 人关注过本帖
标题:vb.net中怎样把listbox1中选中的内容增加到listbox2中
只看楼主 加入收藏
lhj56459897
Rank: 2
等 级:论坛游民
帖 子:19
专家分:47
注 册:2017-7-8
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:6 
vb.net中怎样把listbox1中选中的内容增加到listbox2中
请教各位:中怎样把listbox1中选中的内容增加到listbox2中
搜索更多相关主题的帖子: vb.net 选中 内容 增加 
2018-09-13 20:35
moou
Rank: 2
等 级:论坛游民
威 望:1
帖 子:22
专家分:40
注 册:2018-8-15
收藏
得分:10 
程序代码:
        '遍历listbox1所有项
        For i = 0 To ListBox1.Items.Count - 1
            '清空listbox2
            ListBox2.Items.Clear()
            '向listbox2添加对应的listbox1 的内容
            ListBox2.Items.Add(ListBox1.Items(i).ToString)
        Next
2018-09-17 12:31
moou
Rank: 2
等 级:论坛游民
威 望:1
帖 子:22
专家分:40
注 册:2018-8-15
收藏
得分:5 
回复 2楼 moou
如果只是添加 不用清空listbox2
2018-09-17 12:31
moou
Rank: 2
等 级:论坛游民
威 望:1
帖 子:22
专家分:40
注 册:2018-8-15
收藏
得分:5 
程序代码:
        For Each strCopy As String In listbox1.Items
            listbox2.Items.Add(strCopy)
        Next
2018-09-17 13:10
lhj56459897
Rank: 2
等 级:论坛游民
帖 子:19
专家分:47
注 册:2017-7-8
收藏
得分:0 
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
2018-09-17 23:03
moou
Rank: 2
等 级:论坛游民
威 望:1
帖 子:22
专家分:40
注 册:2018-8-15
收藏
得分:0 
这么长你不烦啊 for each 三行搞定
2018-09-19 16:46
ppppooiiuu
Rank: 1
等 级:新手上路
帖 子:158
专家分:0
注 册:2016-3-2
收藏
得分:0 
2018-09-19 19:09
快速回复:vb.net中怎样把listbox1中选中的内容增加到listbox2中
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015428 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved