OLEDrag&Drop
OLEDrag&Drop
Is it possible to drag items in a listview, and between two listviews? If so, how could I achieve it? I'd love to see a simple example of drag'n'drop in the ExplorerListview.
Thanks
Pete
Thanks
Pete
Re: OLEDrag&Drop
I've modified the drag'n'drop sample, see the attached file. The program contains two list views. You can drag items from the upper to the lower list view. You can also start the program twice and drag items across processes.
I did not implement a Move operation. It would not be much different, the drag source just would have to delete the items after drag'n'drop is complete.
Regards
TiKu
I did not implement a Move operation. It would not be much different, the drag source just would have to delete the items after drag'n'drop is complete.
Regards
TiKu
- Attachments
-
- ExLvwDragDrop.zip
- (156.35 KiB) Downloaded 500 times
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Boycott DRM! Boycott HDCP!
Re: OLEDrag&Drop
Many thanks, TiKu. That's a nice bit of great code.
So that's the way you do when you want to drag'n'drop between two listviews. How about dragging items within the very same listview? I mean, I'd like to drop an item (or some items if I had more of them selected) over the item that the mouse cursor would have focus on? That's a tricky one, and haven't been able to get it working.

So that's the way you do when you want to drag'n'drop between two listviews. How about dragging items within the very same listview? I mean, I'd like to drop an item (or some items if I had more of them selected) over the item that the mouse cursor would have focus on? That's a tricky one, and haven't been able to get it working.

Re: OLEDrag&Drop
Hi,
I've improved the sample. Now it demonstrates the following things:
Regards
TiKu
I've improved the sample. Now it demonstrates the following things:
- Drop effects Copy and Move, with Move being the default
- On move, the dragged items are removed from the source. You should have a look at how this is done, because you already seem to have implemented it, but in a sub-optimal way.
- Drag'n'Drop within the same control. I implemented it in a way, that allows only dropping on other items but not on the control's background.
- If doing drag'n'drop within the same control, and you're dragging over an item, it will be highlighted as the drop target.
- The sample now uses custom drop descriptions to include the drop target's name in the drop description.
Regards
TiKu
- Attachments
-
- ExLvwDragDrop.zip
- (156.82 KiB) Downloaded 482 times
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Boycott DRM! Boycott HDCP!
Re: OLEDrag&Drop
Thanks again, TiKu.
I tweaked your code a bit so that, once the move drag is over, the items in the source listview get rearranged. Otherwise, you are left with empty spaces between the listitems.
However, I still can't find a method to properly move the listitems within the same listview. So, I reckon I'll have a wait till you get back and instruct me how to do it.
Kind regards,
Pete
I tweaked your code a bit so that, once the move drag is over, the items in the source listview get rearranged. Otherwise, you are left with empty spaces between the listitems.
Code: Select all
Private Sub ExLVwU_OLECompleteDrag(ByVal data As ExLVwLibUCtl.IOLEDataObject, ByVal performedEffect As ExLVwLibUCtl.OLEDropEffectConstants)
If performedEffect = odeMove Then
Call ExLVwU.DraggedItems.RemoveAll(True)
'rearrange items in source listview
ExLVwU.ArrangeItems astDefault
End If
End Sub
Kind regards,
Pete
Re: OLEDrag&Drop
Ah, so you want to change the items' position via drag'n'drop? Okay, I'll implement that when I'm back.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Boycott DRM! Boycott HDCP!
Re: OLEDrag&Drop
Yes, that's what I'd like to achieve. Sorry for the misunderstanding.TiKu wrote:Ah, so you want to change the items' position via drag'n'drop? Okay, I'll implement that when I'm back.

Looking forward to your solution.

Re: OLEDrag&Drop
See the attached file...
- Attachments
-
- ExLvwDragDrop.zip
- (158.61 KiB) Downloaded 479 times
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Boycott DRM! Boycott HDCP!
Re: OLEDrag&Drop
Thanks again for the sample project.
I've been quite busy recently, so I couldn't get back to the topic.
The thing is, I'm trying to drag items, including their subitems, between two Listviews and within the same Listview in the Report view. The code you provided is somehow different to what I want to achieve. I attach my file to show what I've managed to do so far.
The issue concerning dragging items between two different Listviews has been solved by you in a succesful fashion to some extent. Thanks for that again. However I try, I still fail to figure out how to drag subitems together with the Listitems Text. And I'm still struggling to do a similar thing with the drag'and'drop within the same Listview.
I'd appreciate it if you could look into my file attached and point me to the right direction.
Regards,
Pete
I've been quite busy recently, so I couldn't get back to the topic.
The thing is, I'm trying to drag items, including their subitems, between two Listviews and within the same Listview in the Report view. The code you provided is somehow different to what I want to achieve. I attach my file to show what I've managed to do so far.
The issue concerning dragging items between two different Listviews has been solved by you in a succesful fashion to some extent. Thanks for that again. However I try, I still fail to figure out how to drag subitems together with the Listitems Text. And I'm still struggling to do a similar thing with the drag'and'drop within the same Listview.
I'd appreciate it if you could look into my file attached and point me to the right direction.
Regards,
Pete
- Attachments
-
- ExLvwDragDrop.zip
- (298.92 KiB) Downloaded 471 times
Re: OLEDrag&Drop
Hi,
I'm in holiday until the mid of January and do only have a smartphone with me.
To drag sub-items, too, you'll have to extend the user-defined type that I use to store the dragged items' data. It needs to include the sub-items' data as well. When storing the dragged item in the type, you also need to store the sub-item data into it. And when loading the item data from the type, you also need to load the sub-items from it.
I'm in holiday until the mid of January and do only have a smartphone with me.
To drag sub-items, too, you'll have to extend the user-defined type that I use to store the dragged items' data. It needs to include the sub-items' data as well. When storing the dragged item in the type, you also need to store the sub-item data into it. And when loading the item data from the type, you also need to load the sub-items from it.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Boycott DRM! Boycott HDCP!
Re: OLEDrag&Drop
Thanks for the info, Tiku. I'll try my best to do that while you're away on holiday. Once I'm successful, I'll upload it on to the forum. If not, then I'll have to wait for your solution, however long that might be.
Pete
Update
Yep, I managed to do that, in a way that serves my own purpose pretty well.
Now going on to resolve the issue with dragging Listview items and subitems within the same Listview control.
Regards,
Pete

Pete
Update
Yep, I managed to do that, in a way that serves my own purpose pretty well.
Code: Select all
Private Type LISTITEMDATA
ItemText As String * 200
SubText(1 To 2) As String * 200 'this is my inclusion for my own purpose - I work only on 2 subitems in each Listview
IconIndex As Long
ItemData As Long
OverlayIndex As Long
End Type
Private Sub ExLVwU_OLESetData(ByVal data As ExLVwLibUCtl.IOLEDataObject, ByVal formatID As Long, ByVal Index As Long, ByVal dataOrViewAspect As Long)
Dim i, j As Long 'one more dimension 'j' for my own purpose - I'll be using it in a loop for the Listview Subitems
[...]
For Each itm In ExLVwU.DraggedItems
itmData.ItemText = Left$(itm.Text, 200)
For j = 1 To 2 'here's the dim - I've got only 2 subitems in a Listview
itmData.SubText(j) = Left$(itm.SubItems(j), 200) 'each Subitem text is allocated to the itmData.SubText(j)
Next
itmData.ItemData = itm.ItemData
[...]
Private Sub ExLVwU2_OLEDragDrop(ByVal data As ExLVwLibUCtl.IOLEDataObject, effect As ExLVwLibUCtl.OLEDropEffectConstants, dropTarget As ExLVwLibUCtl.IListViewItem, ByVal button As Integer, ByVal shift As Integer, ByVal x As Single, ByVal y As Single, ByVal hitTestDetails As ExLVwLibUCtl.HitTestConstants)
Dim i, j As Long 'same here
[...]
Set itm = ExLvwU2.ListItems.Add(Trim$(itmData.ItemText), , itmData.IconIndex, , itmData.ItemData)
For j = 1 To 2 'same here
itm.SubItems(j).Text = Trim$(itmData.SubText(j)) 'same here
Next
itm.OverlayIndex = itmData.OverlayIndex
[...]

Regards,
Pete
- Attachments
-
- ExLvwDragDrop.zip
- (309.33 KiB) Downloaded 464 times
Re: OLEDrag&Drop
Hallelujah! I've made it work! 
There's, however, one thing I'd like to get sorted out - every time you drag'n'drop items, you are left with the one item having that rectangular focus left on it. How to get rid of it and make it appear on the item that was dragged and moved into a new position?

There's, however, one thing I'd like to get sorted out - every time you drag'n'drop items, you are left with the one item having that rectangular focus left on it. How to get rid of it and make it appear on the item that was dragged and moved into a new position?

Last edited by engee30 on 24 Dec 2012, 14:08, edited 2 times in total.
Re: OLEDrag&Drop
Could it be that you are talking about the DropHilitedItem? If so, you only need to set the control's DropHilitedItem property to Nothing. Otherwise set the CaretItem property to Nothing.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Boycott DRM! Boycott HDCP!
Re: OLEDrag&Drop
Yes, that was all about the Caret property. Many thanks Tiku. 
The whole thing with the Drag'n'drop seems to be sorted out now.
Kind regards,
Pete

The whole thing with the Drag'n'drop seems to be sorted out now.
Kind regards,
Pete
- Attachments
-
- ExLvwDragDrop.zip
- (153.18 KiB) Downloaded 459 times
Re: OLEDrag&Drop
It's me again, but this time I've got a question about Sorting. Here's the code I've applied to my Listview:
Basically, the problem occurs when there's a digit in the Listview text, or in its Sub-text(s). If I sort a column of Listview item texts:
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
I get something like this (soDescending order):
Item 9
Item 8
Item 7
Item 6
Item 5
Item 4
Item 3
Item 2
Item 10
Item 1
and then back like this (soAscending order):
Item 1
Item 10
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
What to do to make that Item 10 appear in the correct position, before neither Item 1 (in soDescending SortOrder), nor Item 2 (in soAscending SortOrder)?
Code: Select all
Private Sub ExLVwU_ColumnClick(ByVal column As ExLVwLibUCtl.IListViewColumn, ByVal button As Integer, ByVal shift As Integer, ByVal x As Single, ByVal y As Single, ByVal hitTestDetails As ExLVwLibUCtl.HeaderHitTestConstants)
If ExLVwU.SortOrder = soDescending Then
ExLVwU.SortOrder = soAscending
Else
ExLVwU.SortOrder = soDescending
End If
Select Case column.Index
Case 0
ExLVwU.SortItems sobText, , , , , 1, False
Case 1
ExLVwU.SortItems sobText, , , , , 1, False
Case 2
ExLVwU.SortItems sobText, , , , , 1, False
End Select
End Sub
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
I get something like this (soDescending order):
Item 9
Item 8
Item 7
Item 6
Item 5
Item 4
Item 3
Item 2
Item 10
Item 1
and then back like this (soAscending order):
Item 1
Item 10
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
What to do to make that Item 10 appear in the correct position, before neither Item 1 (in soDescending SortOrder), nor Item 2 (in soAscending SortOrder)?
