getting SelectedItem on MouseRightButtonDown or when openning the contextMenu

2 posts, 0 answers
  1. Victor
    Victor avatar
    2 posts
    Member since:
    May 2011

    Posted 03 May 2011 Link to this post


    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:
    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.
  2. Tina Stancheva
    Tina Stancheva avatar
    3298 posts

    Posted 06 May 2011 Link to this post

    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.

    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. DevCraft R3 2016 release webinar banner
Back to Top