Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Windows Form TreeView Sort after LabelEdit

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?

like image 986
blu Avatar asked Apr 30 '09 19:04

blu


1 Answers

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));
}
like image 81
m_collard Avatar answered Sep 22 '22 00:09

m_collard