As the title suggest I have the following treeview:
Everything works as expected, except when the SelectedItem changes the tree won't expand to the level, unless that level has been navigated to previously, but the item itself still gets selected.
I was under the impression that by setting IsVirtualizing and IsLoadOnDemandEnabled to False would have cleared this issue, but no change in behavior was observed.
<
telerik:RadTreeView
IsEditable
=
"False"
ItemsSource
=
"{Binding Items}"
SelectedItem
=
"{Binding SelectedItem, Mode=TwoWay}"
IsLineEnabled
=
"True"
IsRootLinesEnabled
=
"False"
Background
=
"White"
telerik:AnimationManager.IsAnimationEnabled
=
"False"
IsVirtualizing
=
"False"
IsLoadOnDemandEnabled
=
"False"
AutoScrollToSelectedItem
=
"True"
/>
Everything works as expected, except when the SelectedItem changes the tree won't expand to the level, unless that level has been navigated to previously, but the item itself still gets selected.
I was under the impression that by setting IsVirtualizing and IsLoadOnDemandEnabled to False would have cleared this issue, but no change in behavior was observed.
5 Answers, 1 is accepted
0
Hello Dmitri,
Note that when you select an item programmatically and this item haven't been expanded yet, the tree won't scroll to it. This is because the item's container is not yet generated. In order to scroll to the selected item you can use the SelectItemByPath() or BringPathIntoView() methods of the RadTreeView.
To use this approach basically you will need to add a string property in your business object that holds the path to the element.
Then set the TextSearch.TextPath attached property on the treeview. The value of the attached property should be set to the name of the property that is used for constructing the path.
Here is an example with the SelectItemByPath():
For your convenience I attached a sample project with the described approach. Please let me know if it works for you.
Regards,
Martin
Telerik
Note that when you select an item programmatically and this item haven't been expanded yet, the tree won't scroll to it. This is because the item's container is not yet generated. In order to scroll to the selected item you can use the SelectItemByPath() or BringPathIntoView() methods of the RadTreeView.
To use this approach basically you will need to add a string property in your business object that holds the path to the element.
public
class
MyDataItem
{
........
public
string
Path {
get
;
set
; }
public
string
Header {
get
;
set
; }
}
<
telerik:RadTreeView
TextSearch.TextPath
=
"Header"
/>
var vm =
this
.DataContext
as
ExampleViewModel;
MyDataItem item = vm.Items.First().Children[1];
var path = item.Path;
this
.Tree.SelectItemByPath(path);
For your convenience I attached a sample project with the described approach. Please let me know if it works for you.
Regards,
Martin
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
Dmitri
Top achievements
Rank 1
answered on 27 May 2014, 07:47 AM
Is it possible to load the entire tree? There are certain objects I have no direct ability to inherit or override.
0
Hello Dmitri,
Keep in mind that I don't recommend you to pre-load the entire treeview, because in a scenario with big amount of items this approach will be slow. This is why I can suggest you another option that you can use. Basically you can create wrappers for your objects and pass them to the tree instead of your original models. This will allow you to create additional properties and behavior for the business objects, therefore you will be able to use the approach with the SelectItemByPath() method.
Please give approach a try and let me know if it helps.
Regards,
Martin
Telerik
Keep in mind that I don't recommend you to pre-load the entire treeview, because in a scenario with big amount of items this approach will be slow. This is why I can suggest you another option that you can use. Basically you can create wrappers for your objects and pass them to the tree instead of your original models. This will allow you to create additional properties and behavior for the business objects, therefore you will be able to use the approach with the SelectItemByPath() method.
Please give approach a try and let me know if it helps.
Regards,
Martin
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
Dmitri
Top achievements
Rank 1
answered on 28 May 2014, 05:11 PM
It's a small but potentially "deep" tree I was hoping for the quickest solution, so I was hoping to avoid wrapping dozens of potential objects.
0
Hello Dmitri,
You can load the entire tree if you use the ExpandAll() method (then CollapseAll() to collapse the nodes again). Please note that this method iterates recursively through the treeview and creates an container for each item in the ItemsSource. This might be a slow operation if your tree has many items (including in depth). That's the reason why I suggested you to use wrappers. You will need to write little more code but it will allow you to use the SelectItemByPath() method and in scenarios with big amount of data this will greatly improve the performance.
In addition would you mind telling me how deep your treeview can get (maximum levels you can have)? Thank you in advance for the information.
Regards,
Martin
Telerik
You can load the entire tree if you use the ExpandAll() method (then CollapseAll() to collapse the nodes again). Please note that this method iterates recursively through the treeview and creates an container for each item in the ItemsSource. This might be a slow operation if your tree has many items (including in depth). That's the reason why I suggested you to use wrappers. You will need to write little more code but it will allow you to use the SelectItemByPath() method and in scenarios with big amount of data this will greatly improve the performance.
In addition would you mind telling me how deep your treeview can get (maximum levels you can have)? Thank you in advance for the information.
Regards,
Martin
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.