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

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

3 Answers 34 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
GEB
Top achievements
Rank 1
GEB asked on 28 May 2010, 08:54 PM
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?

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 31 May 2010, 08:53 AM
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.
0
Niels
Top achievements
Rank 1
answered on 14 Mar 2011, 01:11 PM
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

196451_314398-treeviewexample

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

private

 

 

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.

/Niels

0
Tina Stancheva
Telerik team
answered on 17 Mar 2011, 02:17 PM
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.

Regards,
Tina Stancheva
the Telerik team
Tags
TreeView
Asked by
GEB
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Niels
Top achievements
Rank 1
Share this question
or