NickHallick
NickHallick

Reputation: 239

Cutting and pasting nodes in a TreeView control?

I'm looking to implement a cut and paste method to replace drag and drop in a TreeView control. Drag and drop no longer works in the TreeView, and I believe cut and paste will be easier for the people using it. In this TreeView, I will be working with cutting only the child nodes. This object has only parent and child nodes (parent being dates and child nodes being purchase orders.) I'm not sure if there is a cut property and/or paste property to use with treeview1.node.selected or whatever I need to use.

Upvotes: 0

Views: 500

Answers (1)

Alex K.
Alex K.

Reputation: 175766

... upon clicking cut it copies the selected node to copynode. then remove the selected node. so the node is stored in the copynode slot

This won't work as copynode is a reference to the thing you just removed (destroyed) so after removal copynode will point to Nothing.

Instead; when a cut event occurs store the key features of the cut node (text, key, icon index etc.) in to a module level user defined type (or delimited string/class/series of variables) and remove the node. You can then use this data as the basis to construct a new node when a paste event is raised.

(The cut/paste events are not bound to the windows clipboard, rather thay are your own inventions based upon a context menu/detection of ctrl+X/V)

im not sure how to check if the node has children when im pasting to it

if tv.SelectedItem.Children > 0 then
   ... got child nodes

Upvotes: 1

Related Questions