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

Scrolling to item in tree has problems

2 Answers 152 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 29 Mar 2018, 12:43 AM

Actually there are a couple of issues here.

  • No search panel available for the TreeListView :-(  Setting ShowSearchPanel = true does nothing.

------------------------------------------------

I am running issues with hierarchy items that are expanded while not visible.

 We are using the IsExpandedBinding property which is binding okay, and our data item implements INotifyPropertyChanged.  When you set a node's IsExpanded property, it also recursively set's its parent's IsExpanded property to match.

--------------------------------------------------

  • ScrollIntoView(item) doesn't work with items which were expanded but never visible.  No scroll happens.  ScrollIntoView works with items that were previously or currently visible.  ScrollIntoView(item,true) and the ScrollIntoViewAsync() methods do no better.

I managed to get better results by Scrolling to the item's root, then recursively using ScrollIntoView() on the root to item path.

ex:
A
  B
    C
Doing ScrollIntoView(A), then ScrollIntoView(B), then ScrollIntoView(C) gives better results

But item C is just below the bottom of the grid.  Item B is at the bottom.  This is kind of a 'one off' problem.

----------------------------------------------------

  • Setting SelectedItem isn't working for items recently expanded but never visible.

SelectedItem works ok if the item is visible, or was previously visible.

--------------------------

  I think these problems are happening because when you expand an item while not visible, it does not get into the TreeListView items property until it becomes visible. ExpandHierarchyItem() does not help.

Is there something we can do to help get these newly expanded (but not visible) nodes into the TreeListViews tracked items? (I assume this is the grid.Items collection)

 

2 Answers, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 1
answered on 30 Mar 2018, 03:19 AM

The problem appears to be timing.  After the ScrollToView() is called, the rows are loaded.  There isn't a way to easily tell when the rows are loaded, so the time between completing ScrollToView() and the last row is loaded, the TreeListView isn't usable for the rows being loaded.

I came up with this workaround:

public void ScrollIntoViewExAsync(TreeNode node, bool setSelected)
{
    if(node == null) return;
 
    node.IsExpanded = true;
 
    if (Items.IndexOf(node) == -1)
    {
        var filterDescriptor = new FilterDescriptor<TreeNode>() { FilteringExpression = i => i == node };
        FilterDescriptors.Add(filterDescriptor);
        var itemsToExpand = new List<TreeNode>(Items.OfType<TreeNode>());
        FilterDescriptors.Remove(filterDescriptor);
 
        foreach (TreeNode treeNode in itemsToExpand)
        {
            ScrollIntoView(treeNode);
        }
    }
    else
    {
        ScrollIntoView(node);
    }
 
    Tuple<TreeNode, bool> args = Tuple.Create(node, setSelected);
    Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new DispatcherOperationCallback(UpdateScrollPosition), args);
}
 
public object UpdateScrollPosition(object obj)
{
    var args = (Tuple<TreeNode, bool>) obj;
    var node = args.Item1;
    bool setSelected = args.Item2;
 
    var row = GetRowForItem(node);
    if (row != null)
    {
        row.BringIntoView();
        if(setSelected)
            SelectedItem = node;
    }
    return null;
}
0
Yoan
Telerik team
answered on 02 Apr 2018, 03:15 PM
Hello Dan,

I am glad to hear that you had found a solution to your problem. 

As a side note - I guess that you are familiar with our ScollIntoViewAsync method of the TreeListView. You can use the overload with the expandItem parameter which indicates whether to expand the item. 

Regards,
Yoan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
TreeListView
Asked by
Dan
Top achievements
Rank 1
Answers by
Dan
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or