On demand update

3 posts, 1 answers
  1. VPS
    VPS avatar
    30 posts
    Member since:
    Jan 2015

    Posted 24 May 2018 Link to this post

    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. Answer
    Didi
    Admin
    Didi avatar
    356 posts

    Posted 28 May 2018 Link to this post

    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
  3. VPS
    VPS avatar
    30 posts
    Member since:
    Jan 2015

    Posted 22 Jun 2018 in reply to Didi Link to this post

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

Back to Top