C# 通过递归访问节点的子级

C# 通过递归访问节点的子级,c#,recursion,visual-studio-2005,nodes,C#,Recursion,Visual Studio 2005,Nodes,下面的代码(这一想法归功于Neill Verreyne)用于当选择多个节点(或者更确切地说是子节点)时,这些节点将具有相应的代码,只需单击按钮即可执行。因此,在按钮单击事件中,RecurseTree方法将触发并递归一个xml列表,直到所有选中节点的代码都被执行为止。我现在要做的是,不仅要访问父节点和子节点,还要访问子节点的子节点。是否有任何方法可以做到这一点,我需要向下面提供的代码中添加什么。 谢谢 我用的是VS2005C#。NET 2.0。Winforms private void Recur

下面的代码(这一想法归功于Neill Verreyne)用于当选择多个节点(或者更确切地说是子节点)时,这些节点将具有相应的代码,只需单击按钮即可执行。因此,在按钮单击事件中,RecurseTree方法将触发并递归一个xml列表,直到所有选中节点的代码都被执行为止。我现在要做的是,不仅要访问父节点和子节点,还要访问子节点的子节点。是否有任何方法可以做到这一点,我需要向下面提供的代码中添加什么。 谢谢 我用的是VS2005C#。NET 2.0。Winforms

private void RecurseTree(TreeNode node,string ParentNode)

    if (node.Checked == true)
    {
        //code goes here
        sysvar=[ParentNode];
        sysvar1=[node.Name];
        //and something else
        //with the node's name, a file matching the name of the node would be executed on an external application
    }
    foreach (TreeNode childNode in node.Nodes) RecurseTree(childNode, ParentNode);
}

private void msrstart_Click(object sender, EventArgs e)
{
    if (mMsr != null) mMsr.Start();
    foreach (TreeNode node in treeView1.Nodes) RecurseTree(node, node.Name);   
}
当然,它适用于父节点和子节点。但是我遇到了一个子节点,它有另一个子级节点,上面显示的代码显然只适用于顶级节点和子节点。我想要发生的是,当我选择这个节点(孩子的子节点)时,if语句中的片段也将适用于它,只是有一点不同,其中,sysvar1现在将是
sysvar1=[node.Name]:“childNode.Name]
,这是节点的顶级和第二级。我也在尝试进入第三层。问题是我不知道要操纵哪一个来实现这一点

另外,我不知道如何表达一个适合我问题的问题或陈述。为此,我道歉

如果您想了解以下信息,请摘录XML文件:

<?xml version="1.0" encoding="utf-8"?>
<systemvariables version="4">
    <namespace name="_08_Customer_Diagnostics" comment="">
      <namespace name="_08_10_FreezeFrameData" comment="">
        <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_10_01_FFD_Operation" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
        <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_10_02_Image_FFD" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
        <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_10_01_FFD_Operation_start" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
        <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_10_02_Image_FFD_start" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
      </namespace>
  <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_01_Diag_Customer_Service_0x10" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
  <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_06_Diag_Customer_Service_0x3B_start" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
  <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_05_Diag_Customer_Service_0x30" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
  <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_07_Diag_Customer_Service_0xA0" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
  <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_02_Diag_Customer_Service_0x12" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
  <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_03_Diag_Customer_Service_0x1A_start" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
  <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_08_Diag_Customer_Service_0xA8" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />
  <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="_08_03_Diag_Customer_Service_0x1A" comment="" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="4" maxValuePhys="4" />

</namespace>
</systemvariables>


不清楚你在问什么。已经有一个完整的递归树遍历。XML?请把你的例子(大大)缩小。人们到底期望什么?出了什么问题?我编辑了它,我不确定它现在是否清晰。