How to get an element in a TreeView if a button in the elemt is clicked?

4 posts, 0 answers
  1. GEB
    GEB avatar
    228 posts
    Member since:
    Dec 2008

    Posted 28 May 2010 Link to this post

    I have a 2-level TreeView, and on the children (second level), there is a button in the entry.  That is, each child shows some text, and a button.  When the button is clicked, and an event is generated, how to get the TreeView element that was clicked?  Btw, it will not necessarily be the SelectedItem, because the button may be clicked on a different item.

    Here is a specific example.  The TreeView contains Orders, and Parts within Orders.  The top level of the tree will be the Orders, and under each order will be a list of parts in the tree.  Each Part item will have an 'Edit' button.  When the Edit button is clicked, how to determine the specific TreeView item that contained the edit button so that particular item can be edited?
  2. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 31 May 2010 Link to this post

    Hi GEB,

    If the Edit button is part of the ItemTemplate for the RadTreeViewItem, you can use the UIElementExtension class method ParentOfType() to get the corresponding TreeViewItem.

    I prepared a sample project illustrating this approach. Please give ti a try and let me know if this is what you had in mind.

    All the best,
    Tina Stancheva
    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? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Niels
    Niels avatar
    1 posts
    Member since:
    Feb 2011

    Posted 14 Mar 2011 Link to this post

    TreeView Rad control
    Telerik.Windows.Controls.Navigation  2010.3.1314.1040
    Telerik.Windows.Controls 2010.3.1314.1040
    System.Windows.Interactivity.dll 2.0.20421.0


    When node is expanded using the expasion icon the expanded node is not returned in param in




    void LoadOnDemandCommand(string param)


    Instead the node currently selected is returned (not the expanded node). Thus the result is a bunch of spinning circles.
    I interpret this as that a node is not set to the current item when expanded.
    How is this achieved when using the MVVM pattern. I have had to include an expand event method which sets the expanded node to the SelectedItem.


  4. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 17 Mar 2011 Link to this post

    Hello Niels,

    As I said in the bug report you sent I am not sure that I understand your issue. It seems that you need to bind the LoadOnDemand command to a Command defined in a ViewModel.

    In order to do so you can take advantage of the MVVMLight framework and the EventToCommand behavior in order to pass the LoadOnDemand event args to the ViewModel command thus accessing the RadTreeViewItem that raised the command.

    I will attach the sample project here as well since the community might find it useful. Still, let me know if I am missing something.

    Tina Stancheva
    the Telerik team
Back to Top