I have a list view that i am using in report view. What iam tring to do is allow users to rearrange items by draging them up or down. I am completly sure how i would go about doing this so i am here asking for someone to point me in the right direction please. I am assuming i need to work with LVN_BEGINDRAG but like i said i am not sure how to go about this.
jckl,
As always, look it up on MSDN. I will give you the first helpful point (I am sure there will be others), make sure you are not using ListView_SortItems as it will defeat your (the user's) efforts.
Paul
i have been looking on msdn and i am not using sorting of any kind.
Good, sometimes that flag can sneak in there when you are not looking. Let us know how you make out.
Paul
so far not so good.. i am still tring to figure out how i will make the item move up or down when someone is dragging it.
can anyone point me into what i need to look for in order to find the item number that my mouse is over and how i can move the current selected item to the position of the item i am hovering over?
ok so i finally found a few things that i am half way of getting to work after searching msdn for many many many hours..
invoke MakeDragList,hList
invoke RegisterWindowMessage, ADDR DLM
It seems to be the only way i can find to do this but i am worried i might run into a problem since i am using a listview in report view so i can use checkboxs. I dont know how or if you can use check boxs in a regular listbox. Anyway wish me luck as this has been about a 2 day task so far.
well looking into more of what i was thinking earlier on which i thought wouldnt have worked is i assume this could have been done with LVN_HOTTRACK. The thing is the definition for this on MSDN doesnt sound like i could is for this as it says it requires the extended style and when looking at that makes it sound like it is used to select an item when hovering over it. I didnt think that i could actually use it in this method.
So now i got ways i can play with this and see if i can get it to work how i want.
jckl,
I attached a project that I wrote for Ramon Sala a couple of years ago. You can examine it to see what is done, how. If you examine the following ...
ListBoxProc proc Uses Esi hCtl:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
;---------------------------------------
LOCAL IndexItem:DWORD
LOCAL Buffer[32]:BYTE
;
.if uMsg == WM_LBUTTONDBLCLK
jmp DoIt
.elseif uMsg == WM_CHAR
.if wParam == 13
jmp DoIt
.endif
.endif
jmp EndDo
DoIt: invoke SendMessage, hCtl, LB_GETCURSEL, 0, 0
mov IndexItem, eax
invoke SendMessage, hCtl, LB_GETTEXT, IndexItem, ADDR Buffer
mov eax, hList
.if hCtl == eax
lea esi, rsCreateEditor
invoke lstrcmp, ADDR Buffer, chr$("rsCreateEditor")
cmp eax, 0
je found
lea esi, rsChangeControlColors
invoke lstrcmp, ADDR Buffer, chr$("rsChangeControlColors")
cmp eax, 0
je found
... this is just the first part of the ListBoxProc procedure. The rest of the procedure gets repetitive and is nt need for what I want to show you. As you can see, I am watching for the WM_LBUTTONDBLCLK message. If this message shows up in the queue, then we know that the user has doubleclicked the mouse while hovering over an item in the listbox. When that happens, execution jumps to the DoIt: label where we send the LB_GETCURSEL message to the listbox to get the index number. We can then use that to send the LB_GETTEXT message to the listbox which will load the text of the item that was dubleclicked into the Buffer where you can use it in any way you choose.
Have fun,
Paul
[attachment deleted by admin]
jckl,
Try looking here:
http://www.codeproject.com/listctrl/jianghong.asp
hth,
farrier
ok i have got this working with the first method i came up with but i have one thing that i want to change. When i am dragging an item my mouse cursor changes to a circle with a line. I have tried to set my own cursor but it still replaces mine. Is there a way i can keep this from happening?
You need to load all your cursors as resources, first and then you can alter your program to use a different cursor at various times.
Paul
I got that done and my app does change the cursor but then it get changed again to the cursor that indicates that it is not allowed drops. I am tring to figure out how to either keep the cursor from changing altogether or how to make it allow drops so that i do not get this cursor.
RU willing to post the project? I can help you better that way. When it comes to helping someone while working blind; I do a lousy job. I wish I was better at it. When I have the project, though, that is a different story. I become VERY good.
Paul
dont mind the bad coding habits or sloppy code in it as i am learning on my own. this is my entire project to this point. Also there is a lot of temp code and such in there that will be changed later.
http://www.joresources.com/other/lvdragdrop.zip
I have it, now. I will look at it during lunch.
Paul
ok thanks :bg
Sorry for the delay, I see the problem. I will see what is going on, if I can.
Paul
jckl (How come no vowels?),
You are doing this...
invoke SetCursor, hFinger
... in this area ...
.ELSEIF eax==WM_MOUSEMOVE
... You should move it to this area ...
.ELSEIF eax==WM_LBUTTONDOWN
That is on my hyperlink subclass. The cursor I want to change if for when your dragging an item in my listview. I made the listview a draglist which I think is my problem. The cursor I dont want is the one that shows that the listview is not accepting droping.
Are you sure? I will have to take a look again when I get a chance but if I remember correctly it is tied to the MOUSEMOVE event. That was why I made the suggestion. You need to switch cursors whenever the button is held down during a drag event. Unyil you address that problem it probably wont work.
In any case, loading a cursor is loading a resource. Loaded resources involve memory and that memory needs to be reclaimed when the program is ending. I do not see a DeleteCursor anywhere. Take care of that one, also.
About drag and drop and cursors; a nice example of this is Ewayne Wagners File Manager. You can download it from his website which is http://asmedit.massmind.org/ He uses drag and drop and loads both cursors. It might be fun to look at.
If you have any other questions ...
Paul