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