Welcome Guest Search | Active Topics | Sign In | Register

TreeView - Is there an equivalent for the asp.net treeview's ExpandDepth? Options
Mike B
Posted: Thursday, March 27, 2008 11:49:44 AM
Rank: Newbie
Groups: Member

Joined: 3/27/2008
Posts: 3
Subject says it all - I'm trying to evaluate your treeview control and I'm looking for a way to expand the treeview on the load event. I'm using the ItemPopulate event to control the subNodes.

How can I do this?

Thanks in advance,
Mike
eo_support
Posted: Thursday, March 27, 2008 12:33:26 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi Mike,

No. We do not have such a property. But it's very easy to write one:

Code: C#
private void ExpandNodes(
    EO.Web.TreeNodeCollection nodes, int depth)
{
    if (depth > 0)
    {
        foreach (EO.Web.TreeNode node in nodes)
        {
            node.Expanded = true;
            ExpandNodes(node.ChildNodes, depth - 1);
        }
    }
}


You would then call ExpandNodes(TreeView1.Nodes, depth) to expand the TreeView. For example, calling ExpandNodes(TreeView1.Nodes, 1) would be like setting ExpandDepth to 1 with ASP.NET TreeView.

Feel free to let us know if you have any more questions.

Thanks
Mike B
Posted: Thursday, March 27, 2008 12:44:10 PM
Rank: Newbie
Groups: Member

Joined: 3/27/2008
Posts: 3
Thanks for that. I've added the call to ExpandNodes to my Page_Load event, but that seems to fire before the ItemPopulate event - the result is that the hard coded nodes I've definded are there, but the ItemPopulate event never gets fired to load up the remaining nodes. It also does not fire the ItemPopulate event for the hard coded nodes. In fact, setting a break point in the ItemPopulate event shows that it is never called, even when I click on the treeview control.

Commenting out the ExpandNodes call makes everything behave as expected.

What else am I missing?

Thanks,
Mike
eo_support
Posted: Thursday, March 27, 2008 12:54:28 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi Mike,

No. It does not do that. But it's very easy for you to modify the above code to call it:

Code: C#
private void ExpandNodes(
    EO.Web.TreeNodeCollection nodes, int depth)
{
    if (depth > 0)
    {
        foreach (EO.Web.TreeNode node in nodes)
        {
            node.Expanded = true;

            //Populate child nodes
            TreeView1_ItemPopulate(
                TreeView1, new NavigationItemEventArgs(node));

            ExpandNodes(node.ChildNodes, depth - 1);
        }
    }
}

Thanks
Mike B
Posted: Thursday, March 27, 2008 1:01:08 PM
Rank: Newbie
Groups: Member

Joined: 3/27/2008
Posts: 3
Wouldn't it just be easier to call ExpandNodes after the ItemPoplulate events have fired? I don't really have a treeview until those are called.

My main node says "Companies", to which I add two hard coded ones, then the ItemPopulate event goes out, queries a database, and adds N more nodes. Calling ExpandNodes never fires ItemPopulate for "Companies".

Let me explain a bit more what I'm trying to accomplish, and maybe you can help guide me in a better direction.

Code: C#
Companies
     ->Departments
        ->Users


As the user clicks down through the tree view, the database is queried and the next level is populated. I want to start with the Companies node expanded at least.

Thanks,
Mike
eo_support
Posted: Thursday, March 27, 2008 1:12:48 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi Mike,

The code provided in my second reply calls ItemPopulate for you. So that should solve the problem for you.

There is no point of calling ExpandNodes after ItemPopulate. You do not get the whole tree when ItemPopulate is called from the client side. You only get an "island" branch of the Tree. The whole point of having populate on demand is to avoid loading the whole tree in the memory. And obviously calling ExpandNodes on an island branch does not make any sense.

Hope that helps.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.