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. Image for the cookie policy date
close icon

TreeViewAdv AfterSelct Event

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

1 Reply

RB Rajasekar B Syncfusion Team 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

Loader.
Live Chat Icon For mobile
Up arrow icon