Initial TreeView checkbox click problem

RacingDog

Active Member
Licensed User
This comment relates to the recent thread in the Addition Libraries section, where Derez assures me his TreeViewPlus didn't mess with the event handling of the TreeView. So I'm repeating the info here....

We are talking of a TreeView with checkboxes.

Basically, if the first click on the contol is a check box, it doesn't matter which one, but as well as the check box being ticked, the Root node gets selected and a AfterSelect event occurs during the AfterEvent event, regardless of which node's check box you actually clicked on. This doesn't happen on a plain node selection being your first click. It doesn't happen on any subsequent click.

Another minor query, if I refer to the Root node by node2.Value = tv.GetNode(0), why is node2.IndexOfNode -1? It should surely be the same as the parameter to GetNode, afterall, it is the same node we are talking about.

I was playing with Derez's sample proggy to see how things hung together, so I'll attach the very slightly modified version I was using that found this problem.

Put a break on line 37. Run the prog. Click on any child text box (and nothing else. single step through the evemts to see what I mean. Then continue to Run to see the Root node selection on the control and the text in my little message box.

Continue without the breakpoint and try both the Root check box and the child check box you previously used and note the message box text understand the second comment.

Ta chaps.
 

Attachments

  • tree.sbp
    3.6 KB · Views: 262
Last edited:

RacingDog

Active Member
Licensed User
Just to add to the confusion, if you run it without the breakpoint then the content of message box is different for a first click on a child checkbox, but the Root node still shows as selected. Baffled.
 

agraham

Expert
Licensed User
Longtime User
ControlsEx is an official Basic4ppc library, my extensions are ControlsExDevice and ControlsExDesktop.

The standard Treeview in ControlsEx behaves the same as a TreeviewPlus. The selection of the root when a checkbox is first selected seems to be a "feature" of the underlying .NET control. What I suspect is happening is that the first time the Treeview gets the focus it has to select something if nothing was selected before so it selects the parent node and you get an AfterSelect event because the selection has effectively changed. It seems to not reference the checkboxes in deciding what node to select because the checkboxes are an displayable option and it appears that they are not included in the selection process. You can see this by selecting any node then clicking any other checkbox, the selected node does not change. A bit of an untidy implementation really!

The answer to the second point lies in this line from the help "If the node does not belong to the current node, it will return -1." When you select the root node both node1 and node2 in the example are the root node so node1 does not have a child relationship to node2 so the return value is -1.
 

RacingDog

Active Member
Licensed User
Ah, Gotcha! Yes somewhat untidy.

My second post means I should be able to do what I was hoping to do as it is only the breakpoint which made an unwanted Root IndexOf value appear in place of the child node's value.

Thanks for the info.
 

RacingDog

Active Member
Licensed User
Just to clarify a point....

Further research shows the autoselected node on first click is not the Root, but the tail end of the nodes list in the control (ie all created via the control's AddNewNode method). I was being misled before because the sample I was playing with only had one node in there, the rest being created via node AddNewNode.

It's still a nuisance though.
 
Top