RadTreeView: Expand newly added item

1 Answer 50 Views
TreeView
Alexander
Top achievements
Rank 1
Alexander asked on 31 Oct 2024, 01:48 PM

I want to expand a newly added item in RadTreeView so that the selection is visible. However, as the item is (obviously) not yet visible, the SelectedContainer is (and stays) null. As I am using HierarchicalDataTemplates to create the tree, I don't have the path of the newly created item - so I cannot use 'ExpandItemByPath' (or how can I get the Path for the selected item?).

So how can I find the parents of the recently created Item so that I could expand them?

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 04 Nov 2024, 02:31 PM

Hello Alexander,

In order to expand an item that doesn't have a container yet, you can use the bring-path-into-view feature. The ExpandItemByPath method is part of this feature, so you should be able to use it for your requirement. About the path that you should use, this is part of the item model used to populate the RadGridView. You can see how to construct and use a path in the following article.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Alexander
Top achievements
Rank 1
commented on 12 Nov 2024, 03:39 PM

It's a pity that it seems there is no possibility to automatically find the path of an item in the tree or even to search the tree without knowing the details of the DataTemplates or the underlying data structures. The items are of different types (sometimes even on the same level). They know their children, but (at least in some cases) cannot (by design) know their parents.

Martin Ivanov
Telerik team
commented on 15 Nov 2024, 12:45 PM

The UI virtualization of the control doesn't allow to implement a meaningful and performance-wise mechanism to find a specific element. When the ItemsSource is used, the RadTreeViewItem elements in the nested levels are generated on demand and the control doesn't know about them until the corresponding parent item is expanded. It is more safe to let the developer to define the specific path and the property name which should be used in the path search.

Note that the example from the article relies on a property that holds information about the parent object. However, this is not necessary. You can pre-generate the paths during the initialization of the items where (I guess) you might have access to the parent objects.

Also, if you have a specific idea on how the search can be performed without having the RadTreViewItems generated and without having a path, feel free to share it.

Tags
TreeView
Asked by
Alexander
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or