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

BringIntoViewMode fails to work as expected

4 Answers 190 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Roland Vonk
Top achievements
Rank 1
Roland Vonk asked on 09 Feb 2012, 01:18 PM
We have set the BringIntoViewMode to HeaderAndItems for a particular case and the result is not what I expect. Am I doing something wrong or is there a problem with the TreeView?

In an adapter (as we are building an MVVM application) we attach a handler to the ItemPrepared and LoadOnDemand events.

Originally it seemed logical to simply do the following in the LoadOnDemand event handler:

	var treeViewItem = (RadTreeViewItem) e.OriginalSource;
	treeViewItem.BringIntoView();

But of course should fail since technically the child nodes are not yet loaded.

Than I tried adding the following code to the ItemPrepared event handler:

	e.PreparedItem.BringIntoView();

This of course brings each child node into view as they are being "prepared", so that is also not the desired result. So finally I ended up with:

e.PreparedItem.ParentItem.BringIntoView();

But again no "items" were brought into view (even though in the ItemPrepared event the above code is called for each child node prepared).

Please let me know what I'm doing wrong!

Regards,
Roland

4 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 14 Feb 2012, 07:10 AM
Hi Roland Vonk, 

Invoking the BringIntoView() in the ItemPrepared event could be too early sometimes and it may need a Dispatcher(). However, the best solution in these cases is to use the BringPathIntoView() method which accepts a string path to the desired item and automatically expands and prepares containers on its way through the target item. We highly suggest you to try the BringPathIntoView method, starting with this blog post. Please let us know if you need further assistance on this. 

Regards,
Petar Mladenov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Roland Vonk
Top achievements
Rank 1
answered on 15 Feb 2012, 04:57 PM
Hello Petar,

I cannot seem to get the Dispatcher possibility to work so I've attempted to isolate the "path" of a child element of the expanded node so that I can bring it into view.

if (_associatedControl.SelectedContainer != null)
{
	var childrenCount = _associatedControl.SelectedContainer.Items.Count;
	var scrollToItem = _associatedControl.ContainerFromItemRecursive(_associatedControl.SelectedContainer.Items[(childrenCount > 10) ? 10 : childrenCount - 1]);
	var scrollToItemPath = scrollToItem.FullPath;
	_associatedControl.BringPathIntoView(scrollToItem.FullPath);
}

The idea of course is that since there is limited space in the window with the tree, I don't want to scroll the parent completely out of view. So I've simply decided to try and scroll UP TO the first 10 possible elements.

But it would appear that when I try to retrieve the scrollToItem RadTreeViewItem that children are still not loaded.

At what point can I know for sure that the children are loaded?

Regards,
Roland
0
Petar Mladenov
Telerik team
answered on 16 Feb 2012, 10:16 AM
Hi Roland Vonk ,

 In order to be sure that a RadTreeViewItem has been already generated is to use the ItemPrepared event.
Could you please give it a try and let us know if it helps you?

Greetings,
Petar Mladenov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Roland Vonk
Top achievements
Rank 1
answered on 16 Feb 2012, 02:15 PM
Hello Petar,

Thanks for your recommendations, as this seems to work. I had tried using the ItemPrepared event before but to no avail. With your advice I also used another approach at isolating an element in the parent list. By executing "BringPathIntoView" for each loaded child element as they were loaded (UP TO a maximum e.PreparedItem.Index) I was able to achieve a desirable result.

if (_radTreeView.SelectedContainer != null)
{
var itemIndex = e.PreparedItem.Index;
var itemToBringIntoView = _radTreeView.SelectedContainer.Items[(itemIndex > 9) ? 9 : itemIndex];
var itemContainer = _radTreeView.ContainerFromItemRecursive(itemToBringIntoView);
var itemPath = itemContainer.FullPath;
_radTreeView.BringPathIntoView(itemContainer.FullPath);
}

Its not ideal since BringPathIntoView will be executed for each child loaded, but it works.

Regards,
Roland
Tags
TreeView
Asked by
Roland Vonk
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Roland Vonk
Top achievements
Rank 1
Share this question
or