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

TreeView and MouseRightButton to display context menu

1 Answer 78 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Niranjan
Top achievements
Rank 1
Niranjan asked on 25 Feb 2011, 02:23 PM

Hi

With TelerikRadTreeView , I have various types of items visible in the tree.

The presentation for all tree items is always same and hence I am using single template for displaying all the items.
The difference for these items is in their context menus. For each item, depending on the type different context menus are available.

I am tring to build these context menu dynamically.  To achieve this I am doing following things -

1. RadContextMenu object is created and binded to the treeView.
2. For TreeView control , MouseRightButtonDown and MouseRightButtonUp event is handled.
    MouseRightButtonDown only contains statement e.Handled = true.
    MouseRightButtonUp , clears the items from the context menu , add few items and then IsOpen property of contextmenu is set to true.

To show the context menu properly depending on the item type (binded) I need to know for which radtreeItem mouserightbuttonup event triggered.

Is there any possiblitiy, that I can get the correct radtreeviewItem in mouserightbuttonup event ?
OR
How one can use VisualTreeHelperExtensions functions which gives me correct RadTreeViewItem.

Regards
Rajesh

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 02 Mar 2011, 05:51 PM
Hello Niranjan,

Usually , when you define a RadContextMenu within your RadTreeView, the item under your mouse is getting selected on mouse right button click. Could you try to use the  treeView.SelectedContainer in your MouseRightButtonUp event ?
On the other hand, you could examine the following demo showing a good approach when different types of context menus are needed. Feel free to ask if you need further assistance.

Regards,
Petar Mladenov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
TreeView
Asked by
Niranjan
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or