Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Comments
Sergey Alexandrovich Kryukov 24-Feb-15 0:14am    
Why you can't believe that? Did you even try it? It would be more than natural: you just change one pointer.
—SA
AlwaysLearningNewStuff 24-Feb-15 0:23am    
I am trying to do it right now. I have no idea how to do this. Can you advise me? Thank you for commenting, it is good to "hear: you after such a long time.

Best regards.
Richard MacCutchan 24-Feb-15 4:24am    
That seems quite straightforward, and easy enough to test.

1 solution

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
 
Share this answer
 
v2
Comments
AlwaysLearningNewStuff 24-Feb-15 2:58am    
Sadly, this message adds new item into treeview, the documentation states it clearly.

I have tried something on my own but have failed to succeed...

The more and more I work with this, the more and more I wish to switch to C# and .NET...

If you are 100# sure your approach can work, please help me with some pseudo code or something similar. As always, I will keep trying to solve this on my own...
Sergey Alexandrovich Kryukov 24-Feb-15 8:50am    
I know. I considered this post as a hint for starters. ;-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900