[C#] TreeNode Merge
private vTreeNode DoMerge(vTreeNode source, vTreeNode target)
{
if (source == null || target == null) return null;
foreach (vTreeNode n in source.Nodes)
{
// see if there is a match in target
vTreeNode match = FindNode(n, target.Nodes); // match paths
if (match == null)
{ // no match was found so add n to the target
target.Nodes.Add(n);
}
else
{
// a match was found so add the children of match
DoMerge(n, match);
}
}
return target;
}
private vTreeNode FindNode(vTreeNode source, vTreeNodeCollection nodes)
{
foreach (vTreeNode node in nodes)
{
if (node.TooltipText == source.TooltipText)
return node;
}
return null;
}
參考資料: https://stackoverflow.com/questions/866380/merging-treenodes?answertab=active#tab-top
留言
張貼留言