This control is being studied during this time and something has been found. Let's take a look.
1: click a blank question.
Handle mouse up events
Private void tree_mouseup (Object sender, mouseeventargs E)
{
Point P = new point (E. X, E. y );
Treenode selectnode = authtree. getnodeat (P );
Bool isblank = false;
If (selectnode = NULL)
Isblank = true;
Else
{
If (selectnode. bounds. Contains (E. X, E. y) = false)
Isblank = true;
}
If (isblank)
{
// Blank for processing
}
}
The two methods are mainly based on the mouse coordinates and nodes: Get the node (getnodeat) and node region (bounds) according to the coordinates.
2: check box Selection Problems
My idea is to select all its subnodes when a node is selected. If a node has a subnode selected, this node is selected. Otherwise, this node is not selected.
Node.
Because the aftercheck event is triggered recursively, improper handling will lead to an endless loop. I entered the dead recursion to fill the program stack.
Finally, I added a variable to ensure the continuous starting direction, that is, starting from the original node, updating the parent node up, updating the child node down, and the parent node
The sub-node cannot go down and the sub-node cannot go up. This problem is solved.
Int level =-1;
Private void tree_aftercheck (Object sender, treevieweventargs E)
{
Treenode operatenode = E. node;
If (this. Level =-1)
{
This. Level = E. node. level;
Checkfathernode (operatenode );
Checkallsubnodes (operatenode, operatenode. Checked );
}
Else
{
If (E. node. level <this. Level)
Checkfathernode (operatenode );
Else if (E. node. level> This. Level)
Checkallsubnodes (operatenode, operatenode. Checked );
}
}