Pelles C forum

C language => Beginner questions => Topic started by: CFred on July 25, 2025, 12:19:19 PM

Title: Trreview problem with moving a node
Post by: CFred on July 25, 2025, 12:19:19 PM
The attached program attempts to move a leaf node in a tree when it is dragged to a different position.

The program almost works except if I drag a leaf node to another position and then I drag another leaf mode to make it a child node of the previously dragged leaf node the second dragged node disappears.

I've spent a long time trying to fix this issue without success. Can anybody help me to solve this issue?
Title: Re: Trreview problem with moving a node
Post by: CFred on July 25, 2025, 05:30:31 PM
At last I managed to find a bug in my code at line 560 in the previously uploaded version of the code in the function TREE_MoveSingleBranch().

I changed the line:

tvItem.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_STATE | TVIF_CHILDREN;
to:

tvItem.mask = TVIF_HANDLE | TVIF_TEXT;
I am uploading the working version in case anybody finds it useful (there is very little information on the internet that I could find for dragging tree nodes, particularly as Code Project is no longer available). The code is heavily commented to explain how the it works. I have not tidied up the code so I leave this for anybody who wants to use it.
Title: Re: Trreview problem with moving a node
Post by: John Z on July 26, 2025, 01:52:10 AM
Thanks CFred!

Very nice.  Grabbed it for learning and future reference. 
I've used TreeView quite a bit, but never needed to drag and drop a leaf,

John Z
Title: Re: Trreview problem with moving a node
Post by: CFred on July 28, 2025, 05:47:58 PM
I have updated the demonstration code in previous posts to tidy it up. I have also included the use of two different icons for parent and child nodes and a "No entry" cursor when dragging a node to itself.

The icons taken from The Silk icon pack (was available on the famfamfam website - no longer functioning), whose author is Mark James.

The code needs more work so that subtrees can be moved. I will post a version for moving subtrees once I have developed it fully. At the moment this is work in progress.



Title: Re: Trreview problem with moving a node
Post by: CFred on August 05, 2025, 03:48:01 PM
I have implemented a treeview control with full drop and drag functionality at https://forum.pellesc.de/index.php?topic=11646.0 (https://forum.pellesc.de/index.php?topic=11646.0)