用户完成拖动后重新排列多个选定的列表视图项目。下降 [英] Rearranging multiple selected listview items after user finishes drag & drop

查看:76
本文介绍了用户完成拖动后重新排列多个选定的列表视图项目。下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介:



我正在研究listview的拖放功能。我被困在最后一步 - >用户完成拖放后重新排列多个所选项目。



问题:



你能解释我实现项目重新排列的算法(我希望实现默认的拖放行为)吗?



我有用户释放鼠标后点击项目的索引。我有拖动项目的索引和计数。伪代码也是可以接受的,但要注意我可能会跟进问题。



问候。

解决方案

没有功能可以移动列表中的项目。因此移动过程必须分为删除和插入操作。



对于多个项目,可以通过两种方式完成:在将所有项目插入新位置之前先删除所有选定项目,或对每个项目执行删除/插入。单个项目的示例可以在文章手动重新排序内部项目中找到ListView [ ^ ]。第一种方法要求以某种方式存储所有项目数据(通常在开始拖动操作时在剪贴板中)。



这两种方法都需要在每次删除和插入操作后调整源和目标位置的索引。



第二种方法的伪代码:



  • 迭代所选项目
  • 复制项目数据
  • 删除项目
  • 如果大于已删除项目的索引,则减少插入索引
  • 减少那些大于已删除项目索引的剩余源索引(这将是迭代时的全部内容)从最小到最大的索引执行)
  • 插入项目
  • 增加大于或等于插入索引的剩余源索引
  • 增量插入索引

INTRODUCTON:

I am working on a drag and drop feature of the 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 wish to implement default drag & drop behavior ) ?

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.

Regards.

解决方案

There is no function to move items inside the list. So the move process has to splitted into delete and insert operations.

For multiple items this can be done in two ways: Deleting all selected items first before inserting them at the new position or perform the delete / insert for each item. An example for single items can be found in the article Manual reordering of items inside a ListView[^]. The first method requires that all item data are stored in some way (usually in the clipboard when starting the drag operation).

Both methods require adjusting the indices of the source and destination position after each delete and insert operation.

Pseudo code for the second method:

  • Iterate through the selected items
  • Copy item data
  • Delete item
  • Decrement insert index if greater than index of deleted item
  • Decrement those remaining source indices that are greater than index of deleted item (this will be all when the iteration is performed from smallest to largest index)
  • Insert item
  • Increment those remaining source indices that are greater or equal than the insert index
  • Increment insert index


这篇关于用户完成拖动后重新排列多个选定的列表视图项目。下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆