OLEDrag&Drop

The place for threads about TimoSoft ExplorerListView.
engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

OLEDrag&Drop

Post by engee30 » 20 Nov 2012, 21:08

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

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: OLEDrag&Drop

Post by TiKu » 20 Nov 2012, 23:34

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
Attachments
ExLvwDragDrop.zip
(156.35 KiB) Downloaded 283 times
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: OLEDrag&Drop

Post by engee30 » 21 Nov 2012, 19:54

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.
:|

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: OLEDrag&Drop

Post by TiKu » 22 Nov 2012, 16:21

Hi,

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.
I'll be away for a couple of days, i.e. without access to a programming environment. So if you have more questions, you'll probably need to wait a few days before you get an answer.

Regards
TiKu
Attachments
ExLvwDragDrop.zip
(156.82 KiB) Downloaded 274 times
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: OLEDrag&Drop

Post by engee30 » 23 Nov 2012, 20:08

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.

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
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

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: OLEDrag&Drop

Post by TiKu » 23 Nov 2012, 23:43

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!

engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: OLEDrag&Drop

Post by engee30 » 24 Nov 2012, 16:42

TiKu wrote:Ah, so you want to change the items' position via drag'n'drop? Okay, I'll implement that when I'm back.
Yes, that's what I'd like to achieve. Sorry for the misunderstanding. :oops:
Looking forward to your solution. :idea:

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: OLEDrag&Drop

Post by TiKu » 26 Nov 2012, 20:03

See the attached file...
Attachments
ExLvwDragDrop.zip
(158.61 KiB) Downloaded 264 times
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: OLEDrag&Drop

Post by engee30 » 21 Dec 2012, 14:11

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
Attachments
ExLvwDragDrop.zip
(298.92 KiB) Downloaded 272 times

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: OLEDrag&Drop

Post by TiKu » 21 Dec 2012, 23:42

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.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: OLEDrag&Drop

Post by engee30 » 22 Dec 2012, 11:25

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.

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
[...]
Now going on to resolve the issue with dragging Listview items and subitems within the same Listview control. :geek:
Regards,
Pete
Attachments
ExLvwDragDrop.zip
(309.33 KiB) Downloaded 270 times

engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: OLEDrag&Drop

Post by engee30 » 24 Dec 2012, 10:50

Hallelujah! I've made it work! :ugeek:

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.

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: OLEDrag&Drop

Post by TiKu » 24 Dec 2012, 12:33

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!

engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: OLEDrag&Drop

Post by engee30 » 24 Dec 2012, 14:06

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
Attachments
ExLvwDragDrop.zip
(153.18 KiB) Downloaded 266 times

engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: OLEDrag&Drop

Post by engee30 » 27 Dec 2012, 23:27

It's me again, but this time I've got a question about Sorting. Here's the code I've applied to my Listview:

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
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)? :|

Post Reply