Well, do you have a TreeView.NodeMouseClick event handler method defined and wired? If you have that method you can just call it in your foreach loop as such:
foreach (TreeNode node in treeView1.Nodes)
{
treeView1_NodeMouseClick(node, null);
}
above this statement, in my constructor for example, I have this code
treeView1.NodeMouseClick += new TreeNodeMouseClickEventHandler(treeView1_NodeMouseClick);
And I have a sloppy event handler like:
public void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
TreeNode node = sender as TreeNode;
if (node != null)
MessageBox.Show(node.Text);
}
It should be safe to send in null for the TreeNodeMouseClickEventArgs as long as you don't plan on actually utilizing the event args.
EDITS in response to question edits:
It looks like you should just simply invoke your AfterSelect(...) method via a direct call when your user presses the Expand All button. So, if I am guessing about your architecture properly, you want to add a call to AfterSelect within the click handler of your Expand All button