This is a migrated thread and some comments may be shown as answers.

TreeviewItem IsExpanded and LoadOnDemand

1 Answer 167 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
luc
Top achievements
Rank 1
luc asked on 17 Dec 2014, 09:15 PM
Hi,

I use a treeview with LoadOnDemand enabled. When I expand a node it seems that the property IsExpanded switch from False to True (normal) + switch from True to False (i dont understand) and finally from False to True. We can imagine that final status is the goal, BUT when i expand an empty node the final switch (False to True) dont occurs (think its link with observablecollection)
I join a sample here post. If you open the Root node + open Item node and then try to open empty node SubItem you will see that SubItem IsExpanded property stay false.
What's the issue ?
Regards
Luc 

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 22 Dec 2014, 10:20 AM
Hi Luc,

The RadTreeViewItem has internal coercing logic which checks whether the item to be expanded has any children:
protected internal virtual void OnIsExpandedChanged(bool oldValue, bool newValue)
....
if
(this.Items.Count == 0)
            {
                this.IsExpanded = false;
RadTreeView gives you the ability to expand an item manually by clicking the expander button of the RadTreeViewItem because the IsLoadOnDemandEnabled is set to True. This also gives you the option to add child items on this expand. There are two possible results with such scenario:
-- you expand such item and do not add children (this is what happens in your project on expanding sub item). The result is - the treeview sets IsEsxpanded to true, then it coerces the value back to false because there are no children ( the code from the snippet above kicks in). The expander button is collapsed.
-- you expand such item and set children, for example:
else if (it.Name.StartsWith("SubItem"))
              {
                  it.Items.Add(new Item());
              }
The RadTreeViewItem stays with IsExpanded True and the Expander button is shown as expanded.

Our advice for you is to set IsLoadOnDemandEnabled on RadTreeViewItem level (you can do it via style) and this way you can have expander button only for the items that will receive children from your code.

Regards,
Petar Mladenov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
TreeView
Asked by
luc
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or