syuko

Just For Fun。生存,社会秩序,娱乐
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

RadTreeView:How to Get Item by Path

Posted on 2011-03-18 15:38  syuko  阅读(702)  评论(0编辑  收藏  举报

Telerik官方说:“The RadTreeView API offers you the ability to get an item by path programmatically. This tutorial will show you how to do that.”。并给出了如下的使用方法:

For example, see the following situation - you want to retrieve the treeview item with Header Soccer. In order to do that you need to perform the following steps:

1. Create a path, including only the treeview items' header and using some separator.

2. Set the telerik:TextSearch.TextPath attached property to indicate which property to be used as a path segment.

3. Invoke the GetItemByPath() method of the RadTreeView class. 

和例子:

private void GetTreeViewItemByPath()
{
   
string path = "Sport Categories|Football|Soccer";
   RadTreeViewItem targetItem = radTreeView.GetItemByPath( path,
"|" );
}
其中Telerik列举了很多注意事项,其中有一条是:“Using the GetItemByPath() method of the RadTreeViewItem class is a potentially expensive operation if the item is not visible. The method will recursively expand and scroll items into view, updating the layout numerous times. Almost certainly the method should not be called in a loop (multiple times). If you need to do so, there is probably a better way to achieve what you need.”,这句话说明了节点不可见时是一项比较消耗资源的操作,可Telerik没说当整个RadTreeView不可见(或不属于当前选中窗体)时该方法会返回Null,所以在实际多选项卡的应用程序中,如果调用一个不是当前选项卡页面(或是隐藏)里的RadTreeView的GetItemByPath时一般返回的就是Null。正确的做法是先将该选项卡设为Selected或isHidden=false然后再去GetItemByPath;