开发者

rearranging listview items

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开发者_如何学Go.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜