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

How to reopen rows after data refresh from database

1 Answer 95 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Vesa
Top achievements
Rank 1
Vesa asked on 07 Aug 2013, 02:47 PM
Hi,

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>())

{

     if(row.IsExpanded==true)

     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   
         myTreeListView.ChildrenOfType<Telerik.Windows.Controls.TreeListView.
TreeListViewRow>())

{

    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).?

 

 

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 12 Aug 2013, 10:42 AM
Hello,

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.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
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 >>
Tags
TreeListView
Asked by
Vesa
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or