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

Treelistview getting node on right click

3 Answers 41 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Rajashree
Top achievements
Rank 1
Rajashree asked on 25 Apr 2013, 03:54 PM
I am using MVVM. I wanted to know how to get the Node when you do right click on the node to View Model. My selected node and where am doing the right click is different

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 25 Apr 2013, 08:05 PM
Hi Rajashree,

You need to handle MouseRightButtonDown event, find the element underneath and get its corresponding data item. It could be something like follows:

private void clubsGrid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
       {
           var clickedElement = e.OriginalSource as FrameworkElement;
           if (clickedElement != null)
           {
               var item = clickedElement.DataContext as Club;
           }
       }

If you want to select that item, you can just assign it to the SelectedItem property.

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rajashree
Top achievements
Rank 1
answered on 26 Apr 2013, 06:39 AM
Is there any way that we will get the node without writing code-behind in View (MVVM). Passing this as event argument to some method in view model.
0
Maya
Telerik team
answered on 26 Apr 2013, 01:03 PM
Hi Rajashree,

if you want to keep your code-behind clean, you can either crate an attached behavior and handle the event there (just like in this demo) or work with the patter illustrated in this article (all you need to do in this case is to pass the arguments of the event). 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TreeListView
Asked by
Rajashree
Top achievements
Rank 1
Answers by
Maya
Telerik team
Rajashree
Top achievements
Rank 1
Share this question
or