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 AfterSelect event

Hi,I am using treeViewAdv1_AfterSelect event in treeViewAdv when click the child nodes. However I find there is a bug. It's Ok that I click a node, AfterSelect gets fired, and the SelectedNode is this node. But I cannot fire AfterSelect event when I click this node again because the SelectedNode doesn't change. For example, I click node 1 and node 1 get selected. AfterSelect event gets fired. Now if I click node 1 again, the AfterSelect event will not be fired. How to solve this problem? I need this function of repeatedly selecting the same node.

Beside I also try to use treeViewAdv1_Click event, it can fire click event when I repeatedly click the same node. But it still has problems. When I click on the expand point rather than the child nodes, treeViewAdv1_Click event also gets fired and the treeViewAdv1.SelectedNode within treeViewAdv1_Click is the node selected last time. So it faulsely think I click that node again while actually I click the expand point.

The following is my code:

When using treeViewAdv1_AfterSelect:

void treeViewAdv1_AfterSelect(object sender, EventArgs e)
{
if (this.treeViewAdv1.SelectedNode != null)
{
if (this.treeViewAdv1.SelectedNode.GetPath("") == "Parent" + this.treeViewAdv1.SelectedNode.Text)
{....
....
}
}
}

When using treeViewAdv1_Click:

void treeViewAdv1_Click(object sender, EventArgs e)
{
if (this.treeViewAdv1.SelectedNode != null)
{
if (this.treeViewAdv1.SelectedNode.GetPath("") == "Parent" + this.treeViewAdv1.SelectedNode.Text)
{....
....
}
}
}

Therefore how can I do if I want to fire a event when click child nodes? Meantime I can fire the event again when repeatedly click the same node and It will not fausely be fired when click other things rather than the child nodes.

Look forward to your reply! Thank you very much!

1 Reply

LS Lingaraj S Syncfusion Team August 13, 2010 07:35 PM UTC

Hi Michelle,

Thank you for your interest in Syncfusion products.

Please try using below set of codes to achieve your requirement in TreeViewAdv.

private void Form1_Load(object sender, EventArgs e)
{
this.treeViewAdv1.Click += new EventHandler(treeViewAdv1_Click);
this.treeViewAdv1.BeforeSelect += new Syncfusion.Windows.Forms.Tools.TreeNodeAdvBeforeSelectEventHandler(treeViewAdv1_BeforeSelect);
this.treeViewAdv1.AfterSelect += new EventHandler(treeViewAdv1_AfterSelect);
}
void treeViewAdv1_AfterSelect(object sender, EventArgs e)
{
RaiseClick(this.treeViewAdv1.SelectedNode);
}
void treeViewAdv1_BeforeSelect(object sender, Syncfusion.Windows.Forms.Tools.TreeViewAdvCancelableSelectionEventArgs args)
{
Point pt = this.treeViewAdv1.PointToClient(Cursor.Position);
TreeNodeAdv node = this.treeViewAdv1.GetNodeAtPoint(pt, true);
if (args.Action==TreeViewAdvAction.ByMouse && node == null)
args.Cancel = true;
}
void treeViewAdv1_Click(object sender, EventArgs e)
{
Point pt = this.treeViewAdv1.PointToClient(Cursor.Position);
TreeNodeAdv node = this.treeViewAdv1.GetNodeAtPoint(pt, true);
if (node != null && node == treeViewAdv1.SelectedNode)
RaiseClick(node);
}
void RaiseClick(TreeNodeAdv adv)
{
// please use your code here
}


Please let me know if you have any queries.

Regards,
Lingaraj S.

Loader.
Live Chat Icon For mobile
Up arrow icon