Item selection problem.

6 posts, 1 answers
  1. rubenhak
    rubenhak avatar
    58 posts
    Member since:
    Dec 2008

    Posted 18 Jun 2009 Link to this post

    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.
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 19 Jun 2009 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. rubenhak
    rubenhak avatar
    58 posts
    Member since:
    Dec 2008

    Posted 24 Jun 2009 Link to this post

    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.
  5. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 26 Jun 2009 Link to this post

    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.
  6. rubenhak
    rubenhak avatar
    58 posts
    Member since:
    Dec 2008

    Posted 26 Jun 2009 Link to this post

    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.
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 27 Jun 2009 Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready