News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

TreeView

Started by alan, March 14, 2012, 11:24:21 PM

Previous topic - Next topic

alan

I am looking for some example code for TreeView. I wish to be able to right-click a label in TreeView and move it above the Sibling it is under.. Not by Drag and Drop just by Code.

Any suggestions please?


donkey

You could use WM_CONTEXTMENU to detect the right click, verify that it came from the treeview then copy the item found by TVM_HITTEST, delete it and re-insert it where you want. I wrote a treeview item copy routine for a treeview once that shows most of the functionality your looking for (though not quite the same objective of course). I have cut it out of the main program and built an example project of it (I've added Paste to the demo to demonstrate that though it was not in the original implementation). It doesn't quite do what you need but it demonstrates all of the functions you will have to use.

"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

alan

Thanks.

Have tried the Delete and Insert and it works like a charm except that if the item moved has Children then they are lost.

The Delete deletes the Handle of the label and Insert creates a new one. The Children belonged to the original handle.

I think what is needed is to swap handles on the Insert.AFTER setting so that they are realigned under different Labels. But how that is done is something to learn. Drag and Drop must use a similar idea so it probably swaps the indexes.


donkey

Quote from: alan on March 15, 2012, 09:45:09 PM
Thanks.

Have tried the Delete and Insert and it works like a charm except that if the item moved has Children then they are lost.

The Delete deletes the Handle of the label and Insert creates a new one. The Children belonged to the original handle.

I think what is needed is to swap handles on the Insert.AFTER setting so that they are realigned under different Labels. But how that is done is something to learn. Drag and Drop must use a similar idea so it probably swaps the indexes.



Hi Alan,

Somewhere I have a program that I wrote that does exactly that (moves treeview items with children) I just haven't found the right archive disk yet but have hope, it can't hide forever. I'll post it when I find it.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jj2007

Quote from: alan on March 15, 2012, 09:45:09 PM
The Delete deletes the Handle of the label and Insert creates a new one. The Children belonged to the original handle.

I think what is needed is to swap handle

- Create new handles
- SetParent
- Delete old handles?

donkey

Hi Alan,

Well, I think the program where I used that (or imagined I did) is lost forever. Still, a recursive algorithm can be used to move the items. If you copy the top item to be moved and insert the copy then recurse down through its children doing the same it will work. Then its only a matter of creating an array of the handles that were copied and deleting them, this can be done while copying the items to their new location. Have to take a stab at it...
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

alan

Thanks.

That is terrific code Donkey. Love GoAsm way of doing things.

Will also have a look at the DragAndDrop as it can do that. just have to see what NOTIFY gets handled.

Will keep working at it.

I see the idea of new handles then move children to it. Then delete original. Look at that too. thanks

alan

Worked out a solution.

Use the Item.lParam as an Index for the Siblings.

Item.lParam is always updated when a new label is put into the Tree View so as to keep all Sibling Indexes in consecutive order.

' movie Up
Use the MoveUp Menu function to swap Index of the two lparam. - Selected Item and PreviousItem

Use the TVM_SORTCHILDRENCB Message to sort them.

Works well and keeps all the Children of any moved Label.

Thanks for helping me to brain-storm this one.