Two questions about C # winform Treeview (click the time response in the blank space and select the check box)

Source: Internet
Author: User

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 );
}

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.