Re: Drag 'n drop prob
- From: "Norm Cook" <normcookNOSPAM@xxxxxxxxxxxx>
- Date: Tue, 29 Aug 2006 07:19:18 -0500
"Randy Birch" <rgb_removethis@xxxxxxxx> wrote in message
news:44f38b37$0$17968$c3e8da3@xxxxxxxxxxxxxxxxxxxx
Private Sub Form_Load()
Dim i As Long
For i = 1 To 5
List1.AddItem i
Next i
List1.OLEDragMode = vbAutomatic
List2.OLEDropMode = vbAutomatic
End Sub
Private Sub List1_OLEStartDrag(....)
Data.Clear
Data.SetData List1.List(List1.ListIndex), vbCFText
End Sub
Private Sub ldst_OLEDragOver(....)
If Data.GetFormat(vbCFText) Then
Effect = vbDropEffectCopy Or vbDropEffectMove
Else
Effect = vbDropEffectNone
End If
End Sub
Private Sub List2_OLEDragDrop(....)
List2.AddItem Data.GetData(vbCFText)
'uncomment to remove dropped item from first list
'List1.RemoveItem List1.ListIndex
End Sub
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
Please reply to the newsgroups so all can participate.
"Martin Trump" <martin@xxxxxxxxxxxxxxxxxxx> wrote in message
news:NDkY0YBUe08EFwKT@xxxxxxxxxxxxxxxxxxxxxx
Hi
I want to drag 'n drop from one ListBox to another. I managed to drag 'n
drop from a TextBox to a ListBox mostly by cribbing off the web but when
I try to go ListBox >ListBox nothing happens. Here's the code.
===========================================
Option Explicit
Dim WithEvents lsrc As ListBox
Dim WithEvents ldst As ListBox
'List1/List2 have default properties
Private Sub Form_Load()
Dim i As Long
Set lsrc = List1
Set ldst = List2
For i = 1 To 5
List1.AddItem i
Next i
End Sub
Private Sub lsrc_OLEStartDrag(Data As DataObject, AllowedEffects As
Long)
Data.Clear
Data.SetData lsrc.List(lsrc.ListIndex), vbCFText
End Sub
Private Sub ldst_OLEDragOver(Data As DataObject, Effect As Long, Button
As Integer, Shift As Integer, X As Single, Y As Single, State As
Integer)
If Data.GetFormat(vbCFText) Then
Effect = vbDropEffectCopy Or vbDropEffectMove
Else
Effect = vbDropEffectNone
End If
End Sub
Private Sub ldst_OLEDragDrop(Data As DataObject, Effect As Long, Button
As Integer, Shift As Integer, X As Single, Y As Single)
ldst.AddItem Data.GetData(vbCFText)
End Sub
===========================================
Help appreciated, TIA.
--
Martin Trump
Randy's code works fine but the behavior is that you have to click an item
in List1 and then drag it. Personally, I want the item to start dragging
when I first
select it. A little experimentation led me to add this code to get the
desired effect:
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
List1.OLEDrag
End Sub
.
- References:
- Drag 'n drop prob
- From: Martin Trump
- Re: Drag 'n drop prob
- From: Randy Birch
- Drag 'n drop prob
- Prev by Date: Re: Deploying VB application on Intratnet .. with remote locations systems
- Next by Date: Re: Deploying VB application on Intratnet .. with remote locations systems
- Previous by thread: Re: Drag 'n drop prob
- Next by thread: Re: Drag 'n drop prob
- Index(es):