VB 怎样实现把一个listbox中的选项鼠标拖动到另一个listbox中

 我来答
二白Q0
推荐于2016-05-19 · TA获得超过2413个赞
知道大有可为答主
回答量:990
采纳率:0%
帮助的人:1091万
展开全部
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
百度网友8343d20
2012-05-02 · TA获得超过785个赞
知道小有建树答主
回答量:480
采纳率:100%
帮助的人:247万
展开全部
设置list1的OLEDragMode 为1
list2的OLEDropMode 为1

Private Sub List2_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
List2.AddItem (List1.List(List1.ListIndex))
List1.RemoveItem (List1.ListIndex)
End Sub
追问
你说的是在VB6.0的环境下。我想问的是在VB2008的环境下怎么弄?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式