1

以下に示すように、以下のコードにバグがあります。

このコントロールで実行されているアクションが、間違ったスレッドから呼び出されています。Control.Invoke または Control.BeginInvoke を使用して正しいスレッドにマーシャリングし、このアクションを実行します。

addchildNode()メソッドで。この操作を実行しているときに、このエラーが発生しますthis.Nodes.Insert(pos, oPart);。この問題を解決するために私を助けてください。

public Part GetChildPart(string sKey)
{
    foreach (TreeNode node in this.Nodes)
    {
        Part child = node as Part;
        if (child.Text == sKey) return child;

    }

    //Part Opart = new Part();
    //Opart.Text = sKey;
    //return Opart;

     return null;
} 
public bool AddChildPart(Part oPart)
{
    int pos = 0; // Use for alpha sorted the node

    foreach (TreeNode node in this.Nodes)
    {
        if (node.Tag.ToString() == oPart.Tag.ToString())
        {
            // Avoid duplicate data
            return false;
        }
        else
        {
            if (node.Tag.ToString().CompareTo(oPart.Tag.ToString()) < 0)
            {
                pos++;
            }
        }
    }

    //if (this.TreeView.InvokeRequired)
    //    {
    //        this.TreeView.Invoke((MethodInvoker)delegate()
    //             {
    //                 //inTreeNode.Nodes.Add(tNode2);
    //                 this.Nodes.Insert(pos, oPart//            
    }
    //             );
    //}

    //this.Nodes.Add(oPart);
    this.Nodes.Insert(pos, oPart);--error is here

    //TreeView.Nodes.
    return true;
}

前もって感謝します!

4

0 に答える 0