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