简体   繁体   English

用户完成拖放操作后重新排列多个选定的列表视图项

[英]Rearranging multiple selected listview items after user finishes drag & drop

INTRODUCTON: 介绍使用:

I am working on a drag and drop feature of the listview. 我正在使用listview的拖放功能。 I am stuck at the last step -> rearranging multiple selected items after user finishes drag and drop. 我停留在最后一步->在用户完成拖放操作后重新排列多个选定的项目。

QUESTION: 题:

Can you explain me the algorithm that implements item rearrangment? 您能解释一下实现项目重排的算法吗?

I have the index of the clicked item after user releases the mouse. 用户释放鼠标后,我具有单击项的索引。 I have indexes of dragged items and their count. 我有被拖动物品及其数量的索引。 Pseudo code is acceptable as well, but be warned that I might have follow up questions. 伪代码也是可以接受的,但请注意,我可能会有后续问题。

NOTE: 注意:

This post has been edited in response to the comments that claimed my original question did not seek user friendly implementation. 这篇帖子已经过修改,以回应声称我的原始问题未寻求用户友好实现的评论。

The point is to implement standard drag & drop behavior, and the reason I phrased my question poorly at the first place was my lack of experience with this topic. 关键是要实现标准的拖放行为,而我之所以不好说这个问题,是因为我对该主题缺乏经验。

If further clarifications are required I will update my post. 如果需要进一步说明,我将更新我的帖子。

Regards. 问候。

Normal drag & drop reordering removes the selected items and reinserts them in the new spot. 常规拖放重新排序将删除所选项目,并将其重新插入新位置。 It would be pretty unintuitive for the existing items in the new spot to jump to where the old ones came from. 让新地点中的现有物品跳到旧物品的来源是很不直观的。

To implement "standard" reordering, basically you: 要实施“标准”重新排序,基本上,您可以:

  • Remember the index of the item below where the user drags your items to. 记住用户将您的项目拖到下面的项目索引。 In your example above, this would be 5 (assuming the new items are to be inserted above Item 6) 在上面的示例中,该值为5 (假设要第6项上方插入新项)
  • Remove the dragged items from the list one at a time using LVM_DELETEITEM 使用LVM_DELETEITEM一次从列表中删除拖动的项目
  • If the dragged items were originally above the new position, subtract the total number of dragged items from the index you remembered in step 1. This would give us 2 using the examples above. 如果所拖动的项目最初位于新位置的上方 ,请从您在步骤1中记住的索引中减去所拖动项目的总数。这将使用上面的示例为我们提供2
  • Finally, reinsert the dragged items at the remembered index (remembering to increment the new index for each additional item). 最后,将拖动的项目重新插入到记住的索引处(记住要为每个其他项目增加新索引)。 For example, the first dragged item would be inserted at position 2 , then the next at 3 and so on. 例如,将第一个拖动的项目插入位置2 ,然后将下一个插入位置3 ,依此类推。

Also note you need special handling for the case where the items are dragged to the top of the list. 还要注意,对于将项目拖到列表顶部的情况,您需要进行特殊处理。 In that case, you would start the insertion at 0 , then 1 and so on. 在这种情况下,您可以从0开始插入,然后从1 ,依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM