Page 1 of 2

How do I drag items between listviews?

Posted: Sat Nov 29, 2003 12:46 am
by storck
Hi all!

I am still having a hard time doing drag and drop. Could anyone please give me an example on how to do drag and drop between two listviews?

I would like to drag an item from one listview and drop it in a position in another listview.

Regards,

Storck

Posted: Sun Nov 30, 2003 2:55 pm
by Num3
Please go to www.purearea.net and visit the code archive...

There are several snippets that show how to use D'N'D

Posted: Sun Nov 30, 2003 6:15 pm
by storck
Thank you! :D

I was beginning to think that I had to go back to Borland C++ Builder becaus of this. That would not have been nice since my project was 80% completed.

Regards,

Storck

May the source be with you all...

Posted: Mon Dec 01, 2003 11:31 am
by Psychophanta
Borland C++ Builder? 2 more people i know and me a little bit, 3 years researching with it, with its internals too. It is a fake: it is base-programmed onto Borland Delphi.
Borland developed firstly Delphi Pascal compiler for windows, and uses it a support to develop C++ Builder compiler.
That's the reason because most of tasks are too slow compiled with it.
Besides of continue bugs in each version.
Objectively VC++ is much better.
And objectively PB is much better than VC++. :D

Posted: Mon Dec 01, 2003 2:00 pm
by storck
I bought BCB3 back in 1998 when it was still affordable and the standard version was not limited to non commercial use. Things are different today.

I am sure VC++ is a better choice, but it has a rather steep learning curve, in my opinion that is. Also, I'm not sure I want to spend the extra dollars.

I love PureBasic. It's just this drag and drop thing. I can drag items between lists. No problem. I would also like the items to be inserted if dropped on anoter item. Or be able to drag item1 and drop it on item3 to rearrange the list. I have not found any example doing that.

I take it that I have to check what item is at the drop x,y position. But right now I can't get it to work. Anyone with an idea?

Regards,

Storck

Posted: Mon Dec 01, 2003 2:15 pm
by Num3
There's a new feature that will come in the new buggy version of Visual Designer 3.81 that does exactly what you want!

If it's done there it means it's also possible for you to make it!

Posted: Mon Dec 01, 2003 3:10 pm
by Fred
Num3 wrote:There's a new feature that will come in the new buggy version of Visual Designer 3.81 that does exactly what you want!
Watch your back, I hear Berikco coming quickly... :wink:

Posted: Mon Dec 01, 2003 8:20 pm
by storck
I have (almost) solved the problem. There is nothing like Win32.hlp. :P Anyways, thank you all for being so supportive. That is one of the thing I love with PureBasic.

C ya!

/Storck

Posted: Sat Dec 06, 2003 9:22 am
by storck
:cry: I am lost. I can drag items in or between list views. I can also get the coordinates from the drop point. What I can't do is to convert the coordinates to the item index in the list.

I have tried using LVM_HITTEST and LVM_GETITEMRECT but whatever coordinates I thorw at them I still just get index 0 returned. :evil:

Please! Anyone?

For me this is the difference between a borland builder 1 Mb app or a PureBasic 50 kB app. I would like to have drag and drop support in the listboxes though. It looks, well more proffesional I guess.

/Storck

Posted: Sat Dec 06, 2003 9:54 am
by Psychophanta
Welcome to the wonderful and incoherent Microsoft WinAPI world :P

Posted: Sat Dec 06, 2003 12:33 pm
by storck
Thank you! :wink:

Posted: Sun Dec 07, 2003 1:52 am
by Doobrey
Don`t forget that once you get it working, MS will bring out a new version of Windows and break your app.. :roll:

Posted: Sun Dec 07, 2003 8:52 pm
by freak
storck wrote:I have tried using LVM_HITTEST and LVM_GETITEMRECT but whatever coordinates I thorw at them I still just get index 0 returned. :evil:
For LVM_HITTEST, you need the coordinates relative to the Gadget corner.
Using WindowMouseX() and substracting GadgetX() doesn't work right,
because WindowMouseX() includes the window border, and GadgetX() doesn't

What I use is this:
(get screen coordinates, and map them directly to the gadget coordinates)

Code: Select all

          UseWindow(#WINDOW_Preferences)
          hittest.LV_HITTESTINFO 
          hittest\pt\x = WindowMouseX() + WindowX() ; WindowMouseX() includes the border size
          hittest\pt\y = WindowMouseY() + WindowY() ; so we first get screen coordinates and map 
                                                    ; them, to the gadget coords
          
          MapWindowPoints_(#NULL, GadgetID(#PrefsDefaultList), @hittest\pt, 1)

          CurrentItem = SendMessage_(GadgetID(#PrefsDefaultList), #LVM_HITTEST, 0, @hittest)          
Timo

Posted: Sun Dec 07, 2003 10:26 pm
by storck
Thank you freak! I will try it out. :P

/Storck

Posted: Mon Dec 08, 2003 7:03 pm
by freak
I wrote a little somthing about that today. See here:
viewtopic.php?p=41351#41351

Timo