通过递归访问子节点

时间:2015-03-10 07:02:12

标签: c# recursion visual-studio-2005 nodes

下面的代码(Neill Verreynne的想法)是为了选择多个节点(或者更确切地说是子节点)时,这些节点将具有相应的代码,只需单击按钮即可执行。因此,在按钮单击事件中,RecurseTree方法将触发并递归xml列表,直到所有已检查的节点为止。代码已被执行。我现在要做的是不仅要访问父节点和子节点,还要访问子节点。有没有办法做到这一点,我需要添加到下面提供的代码。 谢谢! 我正在使用VS 2005 C#。 .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]这是节点的顶级和第二级。我也尝试访问第3级。问题是我不知道为了实现这一点而操纵哪个。

P.S。我并不完全知道如何表达适合我的问题的特定问题或陈述。为此,我道歉。

如果您想知道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>

0 个答案:

没有答案