No background available for pasting a root node

21 hours ago 1
ARTICLE AD BOX

I have a winform with a TreeView which consists of multiple root nodes. My data would not look good with just a single root node.

I require the user to have the ability to click the mouse to add new nodes to the Treeview. If the user clicks a node in the tree then the new node is added as a ChildNode of the clicked node. If the use clicks the empty space below the trees final node a new RootNode is added to the tree. I am using the MouseUp event to determine whether a tree node was clicked or the blank space below the final node was clicked.

TreeNode clickedNode = treeView1.GetNodeAt(e.X, e.Y); if (clickedNode != null) { // User clicked node clickedNode.Nodes.Add("New ChildNode"); } else { // User clicked background treeView1.Nodes.Insert(0, "New RootNode"); }

This works fine until there is no more blank space below the TreeView to click (and scroll bars appear). This is because a node in TeeView consist of the whole horizontal line not just the text label which means there is no longer any blank space in the control to click on to create a RootNode.

enter image description here

The same problem occurs if I use Drag and Drop for moving nodes. Once the new added nodes reach the bottom of the Tree (and scroll bars appear) I cannot drag child nodes from the tree to become root nodes.

A blank line at the bottom of the TreeView would suffice if that is possible.

jonrsharpe's user avatar

jonrsharpe

124k31 gold badges285 silver badges492 bronze badges

tonyk's user avatar

2

Read Entire Article