0

目前,rad 树视图返回重复的子节点。我如何实现,检查子节点是否已经存在。如果已经存在,则不要添加并继续循环。谢谢

私人无效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();
}
4

1 回答 1

0

您提供的片段应该可以满足您的需求。在循环之前将 pnode 初始化为 null,并在循环终止后测试 pnode 的值。

如果这没有帮助,请提供用于添加节点的代码。

于 2013-02-23T11:26:10.080 回答