Question

After a node's label is edited in the tree I try to resort the nodes to place the updated item in the right position. I do this by calling .Sort in AfterLabelEdit event handler which causes an infinite loop.

How can I resort the nodes in a treeview after a label has been changed?

Was it helpful?

Solution

Use BeginInvoke:

    delegate void sort();

    private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
    {
        treeView1.BeginInvoke(new sort(treeView1.Sort));
    }

OTHER TIPS

Use BeginInvoke with a MethodInvoker delegate instead of declaring your own delegate.

private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
    treeView1.BeginInvoke(new MethodInvoker(treeView1.Sort));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top