Welcome Guest Search | Active Topics | Sign In | Register

TreeView: PopulateOnDemand and ExpandAll() Options
UweD
Posted: Monday, August 11, 2008 4:44:14 AM
Rank: Advanced Member
Groups: Member

Joined: 8/11/2008
Posts: 37
I build my TreeView per code. On every new node I set PopulateOnDemand=true. That works fine.
Now I have to move to a definied node per code. I begin at top with ObjStrukt.Nodes[0].ExpandAll(); but nothing happens. The ItemPopulate-event didn't fire.

What shell I do?

Uwe
eo_support
Posted: Monday, August 11, 2008 8:33:50 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

It doesn't appear that ExpandAll triggers ItemPopulate event. All it does is to set the item's Expanded to true. The reason is for most users who use ItemPopulate, the tree is pretty huge. So it's important to call ItemPopulate only when necessary. An unconditional blanket calls to ItemPopulate defeats that purpose.

It should be quite easy for you to write some recursive code to do so. The following is ExpandAll's source code:

Code: C#
public void ExpandAll()
{
    Expanded = true;
    foreach (TreeNode child in SubGroup.Nodes)
        child.ExpandAll();
}


You can enhance it to:

Code: C#
public void ExpandAll()
{
    if (!Expanded)
    {
        //call your ItemPopulate event handler here
    }
    Expanded = true;
    foreach (TreeNode child in SubGroup.Nodes)
        child.ExpandAll();
}


Note this function is on the TreeNode object. So you will want to call this function on each root nodes.

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.