This is not possible. The AfterSelect
event will not be raised again, because the node that was selected is already selected. The selection is not changing, so the event will not be raised.
As Hans points out in a comment to the original question, it's very likely poor UI design to expect a user to realize that clicking again on a node that is already selected will have some sort of effect. The better solution is to add "Refresh" functionality to your application. This is generally mapped to the F5 key, and/or the Ctrl+R keyboard shortcut.
If you absolutely must trigger some action when a node is re-selected, you will need to handle it at a lower level than the AfterSelect
event. And that means figuring out which node the user clicked manually. To do that, handle the MouseDown
event, and use the HitTest
method to determine the node at the location the user clicked. It's not pretty, nor do I recommend it, but it will get the job done.
private void myTreeView_MouseDown(object sender, MouseEventArgs e)
{
TreeViewHitTestInfo info = myTreeView.HitTest(e.X, e.Y);
// Ensure that the user actually clicked on a node (there are lots of areas
// over which they could potentially click that do not contain a node)
if ((info.Node != null) && (info.Node == myTreeView.SelectedNode))
{
// The user clicked on the currently-selected node,
// so refresh the TreeView
// . . .
}
}