Solved

treenodes not expanding when selectednodechanged event defined

Posted on 2008-06-14
3
1,381 Views
Last Modified: 2012-06-27
Hi - I'm using a treeview control in a sharepoint webpart.  It is populating ok and the nodes are expandable normally but when  I add a TreeNodeExpanded event handler to the treeview, nodes after a depth of two stop expanding.  Am I doing something wrong?
When I'm debugging, the treenodexpanded event handler executes regardless of whether the node expands or not.
0
Comment
Question by:millerthegorilla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 

Author Comment

by:millerthegorilla
ID: 21785556
I believe it has something to do with the way I am populating the tree view.  I attach the relevant code.
       /// <summary>
        /// PopulateTreeView is a recursive function, starting at the supplied SPWeb parameter it will extract all relevant information from the site before recursing for each sub site.
        /// </summary>
        /// <param name="web">web is the starting SPWeb (SharePoint web site) for the function.  In this case the current site i.e. the site on which the web part is placed.</param>
        /// <returns></returns>
        /// copied from http://www.sharepointblogs.com/andynoon/archive/2008/03/20/everyone-wants-one.aspx
        public TreeNode PopulateTreeView(SPWeb web)
        {
            TreeNode top = null;
            if (web != null)
            {
                //get detail of this current web
                if(showLinks ) top = new TreeNode("Site Details(" + web.Title + ")", "0", "/_layouts/images/SPHOMESM.GIF", web.Url, "_blank");
                else top = new TreeNode("Site Details(" + web.Title + ")", "0", "/_layouts/images/SPHOMESM.GIF");
                TreeNode node;
                if(showLinks) 
                {
                    node = new TreeNode(web.Title, "root", "/_layouts/images/ICHTT.GIF", web.Url, "_blank");
                    node.ChildNodes.Add(new TreeNode("URL: " + web.Url, "", "/_layouts/images/NEWLINK.GIF", web.Url, "_blank"));
                }
                else
                {
                    node = new TreeNode(web.Title, "root", "/_layouts/images/ICHTT.GIF");
                    node.ChildNodes.Add(new TreeNode("URL: " + web.Url, "", "/_layouts/images/NEWLINK.GIF"));
                }
                TreeNode users = new TreeNode("Users", "", "/_layouts/images/stsicon.gif");
                users.SelectAction = TreeNodeSelectAction.SelectExpand;
                //get all admins
                TreeNode admins = new TreeNode("Administrators (" + web.SiteAdministrators.Count + ")", "", "/_layouts/images/STSPEOPL.GIF");
                foreach (SPUser user in web.SiteAdministrators)
                {
                    TreeNode usr;
                    if (showLinks)
                    {
                        usr = new TreeNode(user.LoginName + "(" + user.Email + ")", "", "/_layouts/images/STAR.GIF", "mailto:" + user.Email, "");
                    }
                    else
                    {
                        usr = new TreeNode(user.LoginName + "(" + user.Email + ")", "", "/_layouts/images/STAR.GIF");
                    }
                    admins.ChildNodes.Add(usr);
                }
                users.ChildNodes.Add(admins);
                //get all groups and users within those groups
                foreach (SPGroup group in web.Groups)
                {
                    //record this group
                    TreeNode grp = new TreeNode(group.Name + " (" + group.Users.Count + ")", "", "/_layouts/images/STSPEOPL.GIF");
                    //for for each user in this group
                    foreach (SPUser user in group.Users)
                    {
                        TreeNode usr;
                        //record this user
                        if (showLinks)
                        {
                            usr = new TreeNode(user.LoginName + "(" + user.Email + ")", "", "/_layouts/images/mysite_titlegraphic.gif", "mailto:" + user.Email, "");
                        }
                        else
                        {
                            usr = new TreeNode(user.LoginName + "(" + user.Email + ")", "", "/_layouts/images/mysite_titlegraphic.gif");
                        }
 
                        grp.ChildNodes.Add(usr);
                    }
                    users.ChildNodes.Add(grp);
                }
                node.ChildNodes.Add(users);
                //get all lists (includes document libraries, discussion forums...)
                TreeNode lists = new TreeNode("Lists and libraries (" + web.Lists.Count + ")", "", "/_layouts/images/sts_list16.gif");
                foreach (SPList list in web.Lists)
                {
                    TreeNode lst = null;
                    try
                    {
                        //an exception can be thrown if an attempt to get the amount of items in a list returns null, also if the list is partially defines an exception may be thrown
                        if(showLinks)
                        {
                            lst = new TreeNode(list.Title + " (" + list.ItemCount + " items)", "", "/_layouts/images/iKpiList.png", list.DefaultViewUrl, "_blank");
                        }
                        else
                        {
                            lst = new TreeNode(list.Title + " (" + list.ItemCount + " items)", "", "/_layouts/images/iKpiList.png");
                        }
                    }
                    catch (Exception)
                    {
                        //if the exception (above) was thrown, just record the name of the list (ignore the amount of items)
                        lst = new TreeNode(list.Title);
                    }
                    lists.ChildNodes.Add(lst);
                }
                node.ChildNodes.Add(lists);
                //recurse for each sub web of the current web
                TreeNode webs = new TreeNode("Sub Webs (" + web.Webs.Count + ")", "", "/_layouts/images/SITEVARIATION.GIF");
                foreach (SPWeb subweb in web.Webs)
                {
                    webs.ChildNodes.Add(PopulateTreeView(subweb));
                }
                node.ChildNodes.Add(webs);
                top.ChildNodes.Add(node);
 
            }
            //return the complete node
            return top;
        }

Open in new window

0
 

Author Comment

by:millerthegorilla
ID: 21786008
I've found part of the problem.  When I comment out the event handler I get javascript:Treeview_togglenode(...  appearing in the status bar of ie when the expand/contract (+/-) sign is rolled over and everything works.  When I uncomment the eventhandler and roll over the +/- sign I get javascript:doPostBack(........,'\t0\\root\\') where the dots are the control reference.  Why does this happen?
0
 

Accepted Solution

by:
millerthegorilla earned 0 total points
ID: 21786167
I've found the solution.  When I am constructing my treenodes in the populatetreeview function I am not passing in a node specific id value. the call should be this:
usr = new TreeNode(user.LoginName + "(" + user.Email + ")", "nodespecificid", "/_layouts/images/STAR.GIF", "mailto:" + user.Email, "");
instead of this:
usr = new TreeNode(user.LoginName + "(" + user.Email + ")", "", "/_layouts/images/STAR.GIF", "mailto:" + user.Email, "");
wahey!
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
checkbox group not updating when none of them is selected 11 45
Check if field exists SPUtility 5 48
What!!!??? 5 61
Pdf not loading 2 40
The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question