We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

TreeViewAdv AfterSelct Event

Thread ID:

Created:

Updated:

Platform:

Replies:

91126 Nov 4,2009 11:15 PM UTC Nov 5,2009 03:37 PM UTC WinForms 1
loading
Tags: Tools
Louis Sicard
Asked On November 4, 2009 11:15 PM UTC

Hi,

I've noticed that the TreeViewAdv AfterSelect event is thrown regardless of where the user has clicked (on a node or not)... Is there anyway to prevent the event to be thrown when the user hasn't actually clicked on a node?

Thanks in advance

Regards

Louis

Rajasekar B [Syncfusion]
Replied On November 5, 2009 03:37 PM UTC

Hi Louis,

You need to get the location of the mouse and then check whether the location is within the node. if not, cancel the BeforeSelect event. It will cancel the AfterSelect event also.

Below is the sample code:


private void treeViewAdv1_BeforeSelect(object sender, TreeViewAdvCancelableSelectionEventArgs args)
{
Point p = Control.MousePosition;
Point p1 = this.treeViewAdv1.PointToClient(p);
treeNode = this.treeViewAdv1.GetNodeAtPoint(p1, true);
if (treeNode != null)
{
if (FindTreeNode(treeNode.Nodes))
{
args.Cancel = false;
}
}
else
{
args.Cancel = true;
}
}

bool FindTreeNode(TreeNodeAdvCollection treeNodeCol)
{
bool nodePresent = false;
foreach (TreeNodeAdv treeNod in treeNodeCol)
{
if (treeNod == treeNode)
{
nodePresent = true;
}
else
{
if (treeNod.HasChildren)
{
FindTreeNode(treeNod.Nodes);
}
}
}
return nodePresent;
}


I have attached the sample.
Let me know if you have any questions.

Thanks,
Rajasekar



TreeViw_7fb5296.zip

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;