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

RadContextMenu on Row Details Table

4 Answers 232 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 24 Jan 2011, 10:38 PM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 27 Jan 2011, 04:22 PM
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>>
0
Adam
Top achievements
Rank 1
answered on 27 Jan 2011, 09:16 PM
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
   
0
Kale
Top achievements
Rank 1
answered on 26 Aug 2016, 01:48 PM
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?
0
Stefan Nenchev
Telerik team
answered on 31 Aug 2016, 11:09 AM
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.
Tags
GridView
Asked by
Adam
Top achievements
Rank 1
Answers by
Maya
Telerik team
Adam
Top achievements
Rank 1
Kale
Top achievements
Rank 1
Stefan Nenchev
Telerik team
Share this question
or