Say I have a listview control with several items in it. How would I allow the user to drag and drop items to rearrange them in the control.
The listview control is in report view, with the full-row select extended style.
Thanks in advance.
Say I have a listview control with several items in it. How would I allow the user to drag and drop items to rearrange them in the control.
The listview control is in report view, with the full-row select extended style.
Thanks in advance.
In your ListView's WM_LBUTTONDOWN
handler, store the currently selected item index somewhere.
In your ListView's WM_LBUTTONUP
handler, use ListView_HitTest()
to determine which item is under the cursor. If different than the stored index, then use ListView_DeleteItem()
and ListView_InsertItem()
to "move" the "dragged" item to the new index.
(Optionally) To help the user see where the item is being "dragged" to, in your ListView's WM_MOUSEMOVE
handler, use ListView_HitTest()
to determine which item is under the cursor, then use ListView_SetItemState()
to disable/enable the LVIS_DROPHILITED
state for the previously "highlighted" item (if any) and to "highlight" the current item.