Thread exception on SelectedNode = .Nodes[0]

374 Views Asked by At

Why do i get System.Threading.ThreadStateException?

void setupTree(TreeView tv, MyObj o)
{

    tv.Invoke((MethodInvoker)delegate
    {
        tv.Nodes.Clear();
        tv.Nodes.Add("<root>").Tag = o;
        tv.SelectedNode = tv.Nodes[0]; //it happens here
    });
}
1

There are 1 best solutions below

4
On

Has the TreeView had its handle created yet?

Could you post a short but complete program to demonstrate this?