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

On demand update

2 Answers 73 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Cleanwatts
Top achievements
Rank 1
Cleanwatts asked on 24 May 2018, 03:32 PM

Does the TreeView support any kind of on demand update?

 

In other words: does it require the entire tree to be available on load, or can a node's children be made available only when expanding the node?

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Didi
Telerik team
answered on 28 May 2018, 03:15 PM
Hello,

In order to achieve the requirement, you could handle the ItemTapped event of the TreeView and in its handler use the Expand method to expand the specific item from the source collection.

Please take a look at the following code example:

private void Tv_ItemTapped(object sender, ItemActionEventArgs e)
        {
            var item = e.Item as Item;
            if (item.Children.Count == 0)
            {
                //populate children collection
                item.Children.Add(new Item() { Children = new List<Item>(), Name = "Added item" });
                //call Expand() with DeviceStartTimer
                Device.StartTimer(TimeSpan.FromMilliseconds(100), () => { this.tv.Expand(item); return false; });
            }
        }

From the code above the item is cast to the business object you're using ( it's Item in the sample). When there are no children, they are added to the Item. In this way, the Expand method works fine on demand update.

I hope I could be of help.

Regards,
Didi
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Cleanwatts
Top achievements
Rank 1
answered on 22 Jun 2018, 03:44 PM

Thanks for your answer. I have managed to get it working without much work.

Tags
TreeView
Asked by
Cleanwatts
Top achievements
Rank 1
Answers by
Didi
Telerik team
Cleanwatts
Top achievements
Rank 1
Share this question
or