How to reopen rows after data refresh from database

2 posts, 0 answers
  1. Vesa
    Vesa avatar
    3 posts
    Member since:
    Jan 2011

    Posted 07 Aug 2013 Link to this post


    I have a WPF solution, where i use treeListView. I populate the treeListView from database and it works ok.

    The problem is that when user has opened several items on treeListView and then tries to get the data again from database. The already opened rows are collapsed. I tried to first go through the treeListView items with this code:

    //First try to get all expanded items to my own list variant (to store ID of all expanded items)

    List<ClsDataOfTreeListItem> Items = new List<ClsDataOfTreeListItem>() ;

    foreach (Telerik.Windows.Controls.TreeListView.TreeListViewRow row in myTreeListView.ChildrenOfType<Telerik.Windows.Controls.TreeListView.TreeListViewRow>())



         Items.Add( (ClsDataOfTreeListItem)row.Item);


    //then i refresh data from the database
    GetData() //this populates data with refreshed contents from DB


    //after refresh, expand the same items again by collected information
    //the problem is, that this time the foreach loop doe not find any rows

    foreach (Telerik.Windows.Controls.TreeListView.TreeListViewRow row in   


        foreach (ClsDataOfTreeListItem itm in Items)


             ClsDataOfTreeListItem tmpItem = (ClsDataOfTreeListItem)row.DataContext;

             if (itm.ID == tmpItem.ID)

                 row.IsExpanded = true;



    //after the operation, the UI is refreshed and the items not expanded, because the foreach loop did not find any rows after data refresh from db.

    Why does the foreach loop detect any rows after data refresh? Is there any way to refresh the UI programmatically before trying to espand as it origanally was? Rebind after data refresh dide not help. Is there any "datarefreshed" event that I could use (the tmpItems could be stored and used in event handler if there is good one for this purpose)?

    Is there any other ways to get and set the original expanded information (and the scrolled position if possible).?



  2. Dimitrina
    Dimitrina avatar
    3769 posts

    Posted 12 Aug 2013 Link to this post


    Do you execute your code (that is called after reloading the data) after the data has loaded into the GridView (for example the DataLoaded event is raised)?

    In general I would suggest you to add a new property to your business object holding an information on its expanded state. Then set the IsExpandedBinding for the TreeListView. You can check our "On-Demand Dataloading" WPF Demo on TreeListView for an example.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top