RadContextMenu on Row Details Table

5 posts, 1 answers
  1. Adam
    Adam avatar
    13 posts
    Member since:
    Jul 2008

    Posted 24 Jan 2011 Link to this post

    All:

    I have followed the examples for adding a RadContextMenu for the header row of a RadGridView and all is working great and it is very useful.  However, I recently added this to another grid which contains a DataTemplate for the row details.  Inside of this data template we have a small RadGridView displaying some other, related data; my problem is that the RadContextMenu.ContextMenu attached property is inheriting down to this grid inside of the Row Details and I cannot figure out how to turn it off.

    I am assuming this is simply a property inheritance from WPF, but I have been unable to determine how to set it back to its default (no / empty) or if this is even possible.  I have tried setting the property value explicitly to null on the row detail's grid, but that had no effect.

    Worst case I can customize a context menu for the details grid, but was hoping to just turn it off altogether.  If anyone could provide any guidance I would really appreciate it.

    Thanks,
    Adam
  2. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 27 Jan 2011 Link to this post

    Hello Adam,

    What you may do is to handle the Opened event of the RadContextMenu and check the type of the clicked item. If it corresponding to the items of the child grid, you can set the IsOpen property of the menu to "False":

    void rowContextMenu_Opened(object sender, RoutedEventArgs e)
            {
                RadContextMenu menu = sender as RadContextMenu;
                var clickedRow = menu.GetClickedElement<GridViewRow>();
     
                Club club = clickedRow.Item as Club;
                if (club != null)
                {
                     
                }  
                else if(club == null)
                {
                    menu.IsOpen = false;
                }
            }

    In this case the Club is the item for the parent grid. Once it is null, you may just  close the RadContextMenu.
     

    Greetings,
    Maya
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Adam
    Adam avatar
    13 posts
    Member since:
    Jul 2008

    Posted 27 Jan 2011 Link to this post

    Maya:

    Thank you for the suggestion - I was trying to avoid doing anything special in the grid, but this type of fix is very clean and easy to implement.  I was able to modify your example slightly to avoid hard-coding a specific data type in there and it is working nicely. Thanks for the support!

    Adam
       
  5. Kale
    Kale avatar
    2 posts
    Member since:
    Jul 2014

    Posted 26 Aug in reply to Adam Link to this post

    Adam, I know it's been a while, but would you be able to post how you were able to accomplish this without referring to the specific data type?
  6. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    281 posts

    Posted 31 Aug Link to this post

    Hi Kale,

    The thread is quite old so I doubt Adam would recall the specific implementation. I am not sure what exactly you aim for but you can use the following approach:

    private void RadContextMenu_Opened(object sender, RoutedEventArgs e)
           {
               RadContextMenu menu = sender as RadContextMenu;
               var clickedRow = menu.GetClickedElement<GridViewRow>();
               if (clickedRow.ParentOfType<GridViewRow>() != null)
               {
                   menu.IsOpen = false;
               }
           }
    This would enable the ContextMenu only for rows of the main grid. Would this work for you? Otherwise, please share more details regarding your setup.

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready