VB 如何把一个listbox作为参数传递

方法一:

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

这样就将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)
        Else
            ListBox2.Items.Insert(item2, item)
        End If
        If e.AllowedEffect = DragDropEffects.Move Then
            ListBox1.Items.Remove(item)
        End If
    End Sub
End Class


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值