Avoid the "C # Treeview nodemousedoubleclick" double-click event error.

Source: Internet
Author: User

When using the winform standard Treeview control, the following similar nodes are added:

Parentnode1

--- Childnode1

--- Childnode2

Parentnode2

--- Childnode1

--- Childnode2

When parentnode2 is collapsed, double-click parentnode2. The node is automatically expanded and the nodemousedoubleclick event will respond. In response to the nodemousedoubleclick event, the treenodemouseclickeventargs ParameterEThere may be confusion. This is mainly because when you double-click the parent node, the child node is expanded or started by default. When you expand or start the child node, treeview automatically adjusts the display position of the node in the font. If there are many sub-nodes and the position is moved, E. node cannot represent the actual double-click node. For exampleProgram. E. node may be childnode1 or childnode2 when you double-click parentnode2. Different parameters may appear because of different locations.

To solve this problem, we should avoid using E. node in actual programming. Instead, we should use treeviewinfo. selectednode to replace the double-click node. This perfectly solves the problem of double-click event behavior disorder. The following is the double-click event that I actually use.Code.

 

Code

     Private     Void  Treeviewinfo_nodemousedoubleclick (  Object  Sender, treenodemouseclickeventargs E)
{
If (E. Button = Mousebuttons. Right)
Return ;
VaR heatrw = Treeviewinfo. selectednode. Tag As Heatreadwrite;
If (Heatrw ! = Null )
{
Heatwriteform HF = New Heatwriteform (heatrw );
HF. showdialog ();
HF. Dispose ();
}
}

 

 

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.