When using the GetItemByPath()
method with databound RadTreeView
there are two approaches. The first approach is to override the ToString()
Its value will be used as path segment. The second approach is to use the telerik:TextSearch.TextPath
attached property to indicate which property will be used for matching.
I will try to explain the GetItemByPath()
method in more details, hopefully that will enable you to find the cause for your issues.
The method takes the string that is passed through the path parameter and searches through the RadTreeView Items
collection to find the first match. The matching mechanism splits the path into parts using the provided separator and compares it to the value of each TreeViewItem
. Then if a RadTreeView i
tem is a match, the method traverse the children of that item for a match to the next part of the path and so on.
However, when the RadTreeView
is databound, the expression that is used to evaluate each RadTreeViewItem
will return different values depending on whether a TextSearch.TextPath
attached property is set and if it isn't - what does the ToString()
method of the corresponding business classes return.
If the TextSearch.TextPath
property isn't set and the ToString()
method isn't overridden, the expression used to evaluate each RadTreeViewItem
in the matching mechanism, will return the name of the corresponding business class, for example _289938_TreeViewContainerBindings.Company
and will use that value to match it with the path parameter. Therefore if the passed path
parameter is for example comp.Name
, the GetItemByPath()
method won't find any matches. And, if you pass comp.ToString()(=_289938_TreeViewContainerBindings.Company)
as a path, the method will compare two identical strings at all times and won't return the corresponding to the path RadTreeViewItem
, but the first match.
However, if the ToString()
method is overridden, for example to return the Name
property of the business class, the expression used to evaluate each RadTreeViewItem
in the matching mechanism, will return also the Name
property. Therefore as the path
can be passed both comp.ToString()
to the GetItemByPath()
method to get the corresponding RadTreeViewItem
In the second approach, the value of the TextSearch.TextPath
property will be used as a path segment. I modified the example project to illustrate this approach so that you can see how it works and choose the best suited approach for you. Also, in the modified project all collections are of type List
which actually doesn't affect the result of the GetItemByPath()
I hope this information will help you. However, if you need more info, please let me know and I will be more than happy to further assist you.
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Telerik Public Issue Tracking
system and vote to affect the priority of the items