目前,rad树视图返回重复的子节点。我如何实现,检查子节点是否已经存在。如果已经存在,则不要添加并继续循环。谢谢
private void BuildProjectTree() {
EntityCollection<ProjectEntity> collection = GetProjectData();
treProjects.Nodes.Clear();
ArrayList pgnodes = new ArrayList();
RadTreeNode pnode = null;
RadTreeNode snode = null;
//MembershipUserCollection membershipCollection = new MembershipUserCollection();
//membershipCollection = Membership.GetAllUsers();
foreach (ProjectEntity p in collection)
{
pnode = null;
foreach (RadTreeNode n in treProjects.GetAllNodes())
{
//bool nodeExist = false;
if (n.Text.Trim() == p.TeamLeader.Trim().ToUpper())
{
pnode = n;
break;
}
}
if (pnode != null)
{
snode = null;
foreach (RadTreeNode n in pnode.Nodes)
{
if (n.Value == p.ProjectSubGroup.ProjectGroup.Name)
{
snode = n;
break;
}
}
if (snode != null)
{
RadTreeNode projectnode = new RadTreeNode(p.ProjectTitle + " (" + p.ReferenceNumber + ")",
p.ProjectId.ToString(), BuildProjectNavigationUrl(p, false));
snode.Nodes.Add(projectnode);
}
}
else
{
RadTreeNode projectteamleadernode = new RadTreeNode(p.TeamLeader.Trim().ToUpper());
RadTreeNode projectgroupnode = new RadTreeNode(p.ProjectSubGroup.ProjectGroup.Name, String.Empty);
RadTreeNode projectnode = new RadTreeNode(p.ProjectTitle + " (" + p.ReferenceNumber + ")",
p.ProjectId.ToString(), BuildProjectNavigationUrl(p, false));
projectgroupnode.Nodes.Add(projectnode);
projectteamleadernode.Nodes.Add(projectgroupnode);
pgnodes.Add(projectteamleadernode);
}
}
foreach (RadTreeNode pg in pgnodes)
{
treProjects.Nodes.Add(pg);
}
//treProjects.ExpandAllNodes();
treProjects.CollapseAllNodes();
}
答案 0 :(得分:0)
您提供的片段应该可以满足您的需求。在循环之前将pnode初始化为null,并在循环终止后测试pnode的值。
如果这没有帮助,请提供您要添加节点的代码。