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

Item selection problem.

5 Answers 137 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
rubenhak
Top achievements
Rank 1
rubenhak asked on 19 Jun 2009, 12:15 AM
Hi,

I'm using RadTreeView on WPF, .NET 3.5 SP1. My goal is to select an item in the treeview programmatically. For this purpose I tried the following:

            tree.SelectedItems.Clear();
            tree.SelectedItems.Add(item);

This works fine IF and ONLY IF this particular item was visible(expanded) at least once. Please help to resolve this issue. All I need is to select the item (no matter if it was expanded or not).

Thanks in advance,
Ruben.

5 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 19 Jun 2009, 12:47 PM
Hi Ruben,

In the current release of our controls, in order to select an item, this item has to be expanded.
If you want to expand it programatically, then you have to call RadTreeView's RadTreeView1.ExpandItemByPath(path, separator) method and after that, get the item using GetItemByPath.

RadTreeView1.ExpandItemByPath(pathToItem, separator); 
 
Dispatcher.BeginInvoke(new Action(() => 
    var expandedItem = RadTreeView1.GetItemByPath(pathToItem, separator); 
    expandedItem.IsSelected = true
}), System.Windows.Threading.DispatcherPriority.ApplicationIdle); 

For our Q2 release, there will be no need for ExpandItemByPath. Also, there will be no need for Dispatcher.

I have attached a sample project demonstrating this functionality.
Take a look at it and if you have further questions or comments, let us know.

Sincerely yours,
Kiril Stanoev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
rubenhak
Top achievements
Rank 1
answered on 24 Jun 2009, 07:11 PM
Kirill,

First of all thanks for quick reply. It basicly helps with the problem. However, I have one more issue with it. 
This solution works fine if the tree height is <= 2. If you try to select the item with path "Item3|Item3.2|Item3.2.1" and modify the MyDataCollection as following:

public MyDataCollection()
{
this.Add(new MyDataObject("Item1"));
this.Add(new MyDataObject("Item2"));

MyDataObject item3 = new MyDataObject("Item3");
item3.SubItems.Add(new MyDataObject("Item3.1"));
item3.SubItems.Add(new MyDataObject("Item3.2"));
item3.SubItems.Add(new MyDataObject("Item3.3"));
this.Add(item3);

             item3.SubItems[1].SubItems.Add(new MyDataObject("Item3.2.1"));

this.Add(new MyDataObject("Item4"));
}

you will see that it would now work. Do you have any suggestions how to make the selection work if I want to select items that are deep inside the tree?

Thank you,
Ruben.
0
Accepted
Kiril Stanoev
Telerik team
answered on 26 Jun 2009, 01:16 PM
Hi Ruben,

The officially released binaries had an issue regarding the scenario you are describing. I have updated the sample project by adding our latest internal binaries. One more modification I made was to change the DataTemplate SubItemTemplate to be HierarchicalDataTemplate. This way you can go as many levels down the hierarchy you want.

In the example, I am demonstrating how to reach item with path "Item3|Item3.2|Item3.2.1|Item3.2.1.1".
Have a look at the example and let me know how this works for you.

Sincerely yours,
Kiril Stanoev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
rubenhak
Top achievements
Rank 1
answered on 26 Jun 2009, 05:28 PM
Hi Kirill,

Now everything works fine. Thank you! 
When are you planning to make an official release of this new version? I'd love to have a full installer rather then individual updated files.

Cheers,
Ruben.
0
Vlad
Telerik team
answered on 27 Jun 2009, 05:33 AM
Hi Ruben,

The release will be next week.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
rubenhak
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
rubenhak
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or