Find the node pointed to by the mouse in the Treeview

Source: Internet
Author: User

When using Treeview, the right-click menu of A treenode is specified, but the Node Selected by right-click is not the node pointed to by the mouse, right-click the function in the menu, and the node to be operated cannot be selectednode. No answer is found for this problem, and a method is found in msdn to use getnodeat (point P) if you know P, you can find the node. The final implementation method is as follows: Find the node through the following code and set this node as selectednode in mousedown, in this way, the selectednode operation may be performed in the right-click menu. note: control is the form where Treeview is located.

/** // <Summary>
/// Obtain the node pointed to by the mouse in the Treeview, and set the node as the currently selected node
/// </Summary>
/// <Param name = "TV"> </param>
/// <Returns> </returns>
Public static treenode getmousenode (Treeview TV, Control)
{
Point Pt = control. pointtoscreen (TV. Location );
Point P = new point (control. mouseposition. X-Pt. X, Control. mouseposition. Y-Pt. y );
Treenode Tn = TV. getnodeat (P );
Return tn;
}

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.