ListBox2.Items.Clear()
For i = 0 To ListBox1.Items.Count - 1
ListBox2.Items.Add(ListBox1.Items(i))
这样就将ListBox1的列表项移动到另一个ListBox2中了
这是利用For循环;提取第一个列表框ListBox1中的所有列表项,再全部加载到另一个listbox2
方法二:更好,但是还没完全看懂,网上搜了一下,都是有关VB.NET的编程
Public Class Form1
'Listbox之间项目拖动示例,左键移动,右键复制
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox2.AllowDrop = True
End Sub
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
Dim DragIndex = ListBox1.IndexFromPoint(e.X, e.Y)
If DragIndex <> ListBox.NoMatches Then
ListBox1.SelectedIndex = DragIndex
If e.Button = Windows.Forms.MouseButtons.Left Then
DoDragDrop(ListBox1.Items(DragIndex), DragDropEffects.Move)
ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
DoDragDrop(ListBox1.Items(DragIndex), DragDropEffects.Copy)
End If
End If
End Sub
Private Sub ListBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragEnter
e.Effect = e.AllowedEffect
End Sub
Private Sub ListBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragDrop
Dim item As Object = CType(e.Data.GetData(GetType(System.String)), System.Object)
Dim item2 As Integer = ListBox2.IndexFromPoint(ListBox2.PointToClient(New Point(e.X, e.Y)))
If item2 = -1 Then
ListBox2.Items.Add(item)
ListBox2.Items.Insert(item2, item)
End If
If e.AllowedEffect = DragDropEffects.Move Then
ListBox1.Items.Remove(item)
End If
End Sub
End Class
方法一:ListBox2.Items.Clear()For i = 0 To ListBox1.Items.Count - 1 ListBox2.Items.Add(ListBox1.Items(i))Next这样就将ListBox1的列表项移动到另一个ListBox2中了这是利用For循环;提取第一个列表框ListBox1中的所有列表项,再全部加载到另一个li
摘要:VB源码,界面编程,ListBox,自定义控件
VB6.0 Listbox 自定义控件例子,相比VB自带的Listbox有以下特点:
1.可以突破Listbox的项目条数上限32767
2.水平滚动条可见
不足之处:添加速度不快,不过和VB自带ListBox控件速度差不多,如果用续表会好很多,留着大家弄吧。
运行环境:Windows/VB6
一、列表简介
一款代替VB自带的ListBox列表控件,多种背景添加样式,改变背景透明度,鼠标热跟踪,指定显示文件夹下的子文件夹和文件,鼠标点开文件夹浏览下一个文件夹,支持撤销功能,自定义改变滚动条样式和颜色,显示项目图标及文件大小等功能。
控件为开源控件,当中包含很多单独功能的函数,对VB初学者来有很大的学习价值,大到每一个函数,小到每一行代码,甚至一个变量,都以中文注释,清晰明了。
分类:标准内部控件、activex控件。
1、标准内部控件:即常用控件,默认显示在工具箱中。
2、activex控件:扩展名为ocx的独立文件,放置于系统中的system或system32目录下。初始状态的工具箱中默认不包括activex。
添加:工程------------部件-------------选择相应的activex控件
3、可插入对象
又称为OLE控件,在VB窗体中可以插入...
给组合框或列表框添加元素一、RowSource属性添加元素二、为工作表中的ActiveX控件中的列表框添加元素三、使用list属性添加元素四、使用additem方法添加列表项五、列表框的其他属性
一、RowSource属性添加元素
Private Sub UserForm_Initialize()
Dim i As Long
i = Sheet5.Cells(Rows.Count,...