Question

I have a TreeView called treeView1, and the following code:

    private void treeView1_AfterExpand(object sender, TreeViewEventArgs e)
    {
        expanded_tree_node = e.Node;
        MessageBox.Show("the node " + expanded_tree_node.FullPath + " was expanded");
        populateTreeViewNode(expanded_tree_node, expanded_tree_node.FullPath, 0);
    }

expanded_tree_node is a reference to a TreeNode.

The message box never shows when I expand nodes. Am I missing something?

I'm just learning C# .Net. Usually I get the skeleton for an event by clicking on a control in Visual Studio. But in this case, I need to type the event name manually based on the MSDN info here. Is there something else I need to do?

Was it helpful?

Solution

The only reason I could see this failing is if the TreeView is not subscribed to the event.

You can subscribe to it via the properties panel at design-time:

enter image description here

Or place this in your constructor:

treeView1.AfterExpand += treeView1_AfterExpand;

OTHER TIPS

In Form1.Design.cs add:

this.treeView1.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterExpand);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top