111,097
社区成员




private TreeNode FindNode(TreeNode tnParent, string strValue)//tnParent根节点,strValue父结点id
{
if (tnParent == null) return null;
if (tnParent.Tag.ToString() == strValue) return tnParent;//找到父结点
TreeNode tnRet = null;
foreach (TreeNode tn in tnParent.Nodes)//根节点下有有子节点,继续遍历
{
tnRet = FindNode(tn, strValue);
if (tnRet != null) break;
}
return tnRet;
}
TreeNode node = FindNode(treeViewFolder.Nodes[0],fatherName);//找父结点
if (node != null)
{
node.Nodes.Add(childNode);//把该子节点加到树上
node.Collapse();
}