Click to See Complete Forum and Search --> : ListBox & OLE Drag


tFrench
June 1st, 1999, 01:42 PM
I have a ListBox control that I want to be able to Drag out of my applicaton. I have all the code inside an OLEDrag_Start sub to handle transfering all the necessary data over to the DATA object that moves the info between apps. The problem is this, I can't figure out how to turn on the OLEDrag property on my form. It's not there. I read somewhere that's all I'd need to do, but nowhere do I see OLEDrag. I have OLEDrop in the properties, just no drag. Is there something I need to include into the project for me to be able to make this work???

Thanks...

Thomas

Ravi Kiran
June 1st, 1999, 11:47 PM
Hi,
Sorry for not replying to the same qn last time.

I hope you are not looking for dragging, like how you do in the IDE. with "clamps" on the control borders!!.
Just implement (i). select the list items and (ii) drag them on to the new control.
For this you dont need to search for OLEDrag property for the form, but for the control .
I give here some code that does this. Try this in sep. project after you get the hang, plug it into your proj.

The scene: 2 Forms - default names.
Each form has 1 label, 1 list box. - def't names
In design mode, change the lisbox MultiSelect to 2, just for ease.

Cut and paste the following code in Form1. The code for the form is identical, except for the 2 lines in Form_load, which will show the other form. Copy it into form2 and remove those lines. And run.
The label provides some feed back. (though not fine..). Select a few items from (either) list and
drop in the other list box. The selected & droped contents gets added to the lis.

You can also select from Explorer a set of files and drag & drop into the list boxes, and you will see the path of the file getting added to the list contents.

Ravi
Code for form1:

option Explicit

private m_dropNo as Integer
private Sub Form_Load()
Label1.Caption = "Drag and Drop the list box contents from the other form"
'
' comment these 2 lines when copied to Form 2.
Form2.Show vbModeless
Form2.Left = me.Left + me.Width
'''
'
With List1
.OLEDragMode = 1
.OLEDropMode = 1
End With
Dim i
for i = 1 to 9
List1.AddItem "Form1,List1:Item:" & Format(i)
' change here also : Leave appropriate line
'List1.AddItem "Form2,List1:Item:" & Format(i)
next i
End Sub

private Sub List1_OLEDragDrop(Data as DataObject, Effect as Long, Button as Integer, Shift as Integer, X as Single, Y as Single)
Dim i, txtbuf
If Data.GetFormat(vbCFText) then
Label1.Caption = "Detected Drop"
txtbuf = Data.GetData(vbCFText)
' parse the data : VB 6.0 has Split fn. (my ver is 5.0)
' i write my own split
m_dropNo = m_dropNo + 1
List1.AddItem "--Drop No:" & Format(m_dropNo) & " -- Text --"
Do
i = InStr(1, txtbuf, vbCrLf)
If i > 0 then
List1.AddItem Left$(txtbuf, i - 1)
txtbuf = mid$(txtbuf, i + len(vbCrLf))
else
List1.AddItem txtbuf ' for the last segment
End If
Loop Until i = 0

ElseIf Data.GetFormat(vbCFFiles) then
Label1.Caption = "Detected Drop"
' if files, add their names as it is:"
m_dropNo = m_dropNo + 1
List1.AddItem "--Drop No:" & Format(m_dropNo) & " -- Files --"
for i = 0 to Data.Files.Count - 1
List1.AddItem Data.Files.Item(i + 1)
next i
else
Label1.Caption = "I dont know how to handle these!!"
End If
End Sub

private Sub List1_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
Label1.Caption = "Detected Contents: Text"
ElseIf Data.GetFormat(vbCFFiles) then
Label1.Caption = "Detected Contents: Files"
else
Label1.Caption = "Detected Contents: Others!"
End If
End Sub

private Sub List1_OLEStartDrag(Data as DataObject, AllowedEffects as Long)
Dim i
for i = 0 to List1.SelCount - 1
If List1.Selected(i) = true then
Data.Files.Add List1.List(i)
End If
next i
End Sub



In this ex, you can ofcourse select, drag & drop into same listbox also, and it will get added!:-)