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

getting SelectedItem on MouseRightButtonDown or when openning the contextMenu

1 Answer 148 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 03 May 2011, 01:10 PM
Hi,

We have a problem with getting the SelectedItem of the RadTreeView
when we right clicking it to show it's ContextMenu.

the solutions that are presented in the posts are both written in the code behind
and involve an explicit casting to a RadTreeView / RadTreeViewItem in order to
get the SelectedItem.

We are looking for a solution where there is no need to use this code in the code-behind:
http://www.telerik.com/community/forums/wpf/treeview/right-click-to-select-item.aspx
as in Syncfusion there is a property: IsSelectOnRightMouseClick that does that.

We are also looking into avoiding mentioning 3rd-party controls in our ViewModel,
in our Syncfusion mockup we are able to produce this handler:

       void OurTree_MouseRightButtonDown(object sender, System.Windows.RoutedPropertyChangedEventArgs<object> e)
        {
            SelectedItem = e.NewValue as OurSpecificObject;
        }

is it possible to do this with telerik?

thank you.

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 06 May 2011, 02:31 PM
Hello Victor,

The RadTreeView.SelectedItem property can be databound to a business property from your view model. This will allow you to define a two-way binding and use the business property to always get the current RadTreeView.SelectedItem.

However, the RadTreeView control doesn't support selection on right-click. So if you need to select the right-clicked item, you will need to implement your own logic. I attached a sample project to illustrate the above suggestions. Please have a look at it and let me know if this is what you had in mind.

Greetings,
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
Tags
TreeView
Asked by
Victor
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or