TreeView and MouseRightButton to display context menu

2 posts, 0 answers
  1. Niranjan
    Niranjan avatar
    23 posts
    Member since:
    Feb 2009

    Posted 25 Feb 2011 Link to this post


    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

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 02 Mar 2011 Link to this post

    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!
  3. DevCraft banner
Back to Top