locked
How to traverse all the parent treeview nodes and highlight one leaf node RRS feed

  • Question

  • User193260626 posted

    Hi,

     

    I am using a Telerik TreeView control on my page. I have the years 2005 - 2011 as the parent node and all the months under a year as the child node. The same page has a gridview also. I have a procedure which looks in the database, starting from the current year and month (using start and end date parameters sent to the storedproc) for each month. When it finds data, say for November 2010, then it should populate the gridview with the data, and open the 2010 node in the Treeview and highlight the November leaf under 2010. I am able to do it for the nodes under the current year. But if there is no data for 2010, then it should look for data under 2009, and highlight say September, 2009. This is where I am having problem. Please let me know how to do it.

     

    I have written the following code

     private void SetTheTreeViewControl(string date)
            {
                    // collapse any open nodes
                    rdDateTree.CollapseAllNodes();
                    // find the node in the tree view
                    RadTreeNode node = rdDateTree.FindNodeByText(date);
                    
                    if (node != null)
                    {
                        // select the node
                        node.Selected = true;
                        // traverse the hierarchy upwards, expanding parent nodes
                        RadTreeNode parentNode = node.ParentNode;
                        while (parentNode != null)
                        {
                            parentNode.Expanded = true;
                            parentNode = parentNode.ParentNode;
                        }
                        // if this is not a leaf node, expand all child nodes
                        if (node.Level != 3)
                        {
                            ExpandAllChildren(node);
                        }
                    }
            }

     

     

    Thursday, December 2, 2010 1:14 PM

All replies

  • User-394672074 posted

    Hi There,

    I can see where you are going, but why don't you rather do a query in the database initially to only select the years/months where data is actually available? And then populate the treeview with only those dates in the hierarchy.

    That way you don't have to worry about no data being available for the selected date. 

    I am sure the change wouldnt be too drastic.

    Hope that helps.

    Thursday, December 2, 2010 3:33 PM