在树视图中移动分支 [英] Moving a branch in treeview

查看:83
本文介绍了在树视图中移动分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了 [ ^ ]建议声明如下:



如果我将节点的子节点移动到新节点,它们的所有后代将随之移动自动,所以不需要递归复制节点。



我真的很喜欢这个想法,但我认为在WinAPI中是不可能的,基于我的阅读文档。



问题:



此信息是否正确 - >你可以通过改变最顶层孩子的父母来真正移动整个分支吗?



如果是,你能告诉我该怎么做吗?

I have stumbled upon this[^] suggestion that claims following:

If I move children of the node to the new node, all their descendants will move with them automatically, so there would be no need for recursive copying of nodes.

I really like this idea, but I do not believe it is possible in WinAPI, based on my reading of the documentation.

QUESTION:

Is this information correct -> can you truly move entire branch by just changing the parent of the topmost child?

If it is, can you show me how to do that?

推荐答案

你知道,我一直在回答你没有实际使用Windows API至少十年的问题,并且从不欣赏C ++这样的语言。我从来没有花过一分钟(我应该说浪费:-))来操纵C ++和原始Windows API中的树视图。然而......



Windows API告诉我们,要插入树视图节点,您必须发送消息 TVM_INSERTITEM 使用 TVINSERTSTRUCT 作为 LPARAM 。换句话说,你给Windows API一个指针:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb773733%28v=vs.85%29.aspx [ ^ ],

https:// msdn .microsoft.com / zh-CN / library / windows / desktop / bb773452%28v = vs.85%29.aspx [ ^ ]。



现在想象你做同样的事情,但不是代表一个树节点的全新结构,而是代表已创建的树节点,该节点包含该节点的所有子树,只是从树视图中分离出来,一些或者另一个。是不是很明显它会附加整个子树?这与树作为数据结构的情况相同。



我也来自一个简单的实用思想:如果Windows API需要递归重新创建子树只是为了将一个父母从一个父母移动到另一个父母,这将是非常愚蠢的API 。我几乎不相信这样的API能够在市场上存活下来。



我希望从这一点开始,你可以继续浏览Windows API,我启动它的方式,并最终确定这个解决方案...... :-)



-SA
You know, I keep answering your questions not having actually use Windows API for at least a decade, and never appreciating such language as C++. And I simply never ever spent a minute (should I say "wasted" :-)) on manipulating of tree views in C++ and raw Windows API. Nevertheless…

Windows API tells us that, to insert a tree view node, you have to send message TVM_INSERTITEM with TVINSERTSTRUCT as LPARAM. In other words, you give Windows API a pointer:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb773733%28v=vs.85%29.aspx[^],
https://msdn.microsoft.com/en-us/library/windows/desktop/bb773452%28v=vs.85%29.aspx[^].

Now imagine that you do the same, but not for a brand-new structure representing a tree node, but representing already created tree node with all the sub-tree of this node, just detached from the tree view, the some or another one. Isn't that apparent that it will attach the whole sub-tree? This is the same as in case of tree as a data structure.

I'm also coming from one simple "practical" thought: if Windows API required recursive re-creation of sub-tree just for moving one from one parent to another, it would be extremely stupid API. I would hardly believe such API could ever survive the market.

I hope that from this point you can continue looking through Windows API, the way I started it, and finalize this solution… :-)

—SA


这篇关于在树视图中移动分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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