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

Programmatically selecting item

3 Answers 111 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Zarko Vorkapic
Top achievements
Rank 1
Zarko Vorkapic asked on 09 Dec 2009, 02:58 PM
Hi,

I think I've tried every possible solution to get this working but for some reason I can't.
Binding on IsSelected property in RadTreeViewItem is not an option.

Using the ContainerFromItemRecursive method I am able to get container of a root item, but when trying to get container of an item that is not root I get null value.

Here is the code block I'm using for this:

void ItemContainerGenerator_StatusChanged(object sender, EventArgs e) 
        { 
            if (TreeViewMain.ItemContainerGenerator.Status == Telerik.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated) 
            { 
                // compares items in TreeViewMain.ItemsSource and _selectedItem and returns object from TreeViewMain.ItemsSource 
                // that has the same type and id as _selectedItem 
                Object item = FindItemInDataSource((IEnumerable)TreeViewMain.ItemsSource, _selectedItem); 
 
                RadTreeViewItem radItem = TreeViewMain.ContainerFromItemRecursive(item); 
 
                if (null != radItem) 
                { 
                    radItem.IsSelected = true
                } 
            } 
        } 

Method FindItemInDataSource works fine and I get the entity I want selected, but ContainerFromItemRecursive method returns null in every case except if item is a root element of a treeview.

Am I doing something wrong or this is just another issue with one of your controls.

Thank you in advance,
Zarko

3 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 09 Dec 2009, 11:47 PM
Hi Zarko Vorkapic,

 If you want the ContainerFromItemREcursive to work the item and its parents should exist and to be generated. If those items are collapsed they are still not generated and this is the reason why you get a null return value.

To accomplish this taks you can use the SelectedItem property of the RadTreeView and to set the item directly. This will select the item, but will not generate it, and thus will not bring it into the viewport. If you want the item to be generated you will need to use the GetItemByPath functionality in order to generated the item, to get the container and to select it.

Mor info is available here:
http://www.telerik.com/help/silverlight/radtreeview-how-to-get-item-by-path.html

and here:
http://www.telerik.com/help/silverlight/radtreeview-how-to-how-to-work-with-selection.html

Please let us know any comments on that. We are not very satisfied with the amount of work that one should do in order to implement this, so we will try to enrichen the API as fas as we can for the next major release.


All the best,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Zarko Vorkapic
Top achievements
Rank 1
answered on 10 Dec 2009, 08:56 AM
Hi Valentin,

I've already read those articles. Perhaps I got something wrong, but as the example states, Path consists of the headers. How can I get those headers dinamically?

Cheers,
Zarko
0
Miroslav
Telerik team
answered on 15 Dec 2009, 11:25 PM
Hi Zarko Vorkapic,

I am sorry for the delayed reply!

 If the TreeView is databound you can set the

telerik:TextSearch.TextPath

property to the name the property on your object that you want to build the path with. Normally this will be a unique property of the object, the Id.

I am attaching a project that shows how you can get an item container that has not been visible before.

Hopefully this will work for you,


Regards,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Zarko Vorkapic
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Zarko Vorkapic
Top achievements
Rank 1
Miroslav
Telerik team
Share this question
or