crash in the handler that moves up a treenode in a treeview c#

Posted by voodoomsr on Stack Overflow See other posts from Stack Overflow or by voodoomsr
Published on 2010-04-21T08:30:42Z Indexed on 2010/04/21 8:33 UTC
Read the original article Hit count: 173

Filed under:
|
|

i have a event handler that moves the selected treenode up. I don't know why is crash in the line with comented. treeviewdocxml is a treeview object, from System.Windows.Forms

        treeViewDocXml.BeginUpdate();
        TreeNode sourceNode = treeViewDocXml.SelectedNode;

        if (sourceNode.Parent == null)
        {
            return;
        }
        if (sourceNode.Index > 0)
        {
            sourceNode.Parent.Nodes.Remove(sourceNode);
            sourceNode.Parent.Nodes.Insert(sourceNode.Index - 1, sourceNode); //HERE CRASH
        }
        treeViewDocXml.EndUpdate();

© Stack Overflow or respective owner

Related posts about treeview

Related posts about c#