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

Custom RadContextMenu per cell

1 Answer 49 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Marcel asked on 05 May 2016, 02:22 PM

Hello,

I want to have a custom contextmenu per cell, I implemented this succesfully with the example given in this thread.

Now I want to add the functionality that the contextmenu will be displayed based on the row where the cursor is and the contextmenu is called, in another thread they point me to the RadContextMenu example of the Telerik Demos. 

So I created a custom class which inherits from the RadContextMenu and attach an implementation for the open event:

protected void GridViewContextMenu_Opened(object sender, RoutedEventArgs e)
{
    RadContextMenu menu = (RadContextMenu)sender;
    GridViewRow row = menu.GetClickedElement<GridViewRow>();
 
    if (row != null)
    {
        row.IsSelected = row.IsCurrent = true;
        GridViewCell cell = menu.GetClickedElement<GridViewCell>();
        if (cell != null)
        {
            cell.IsCurrent = true;
        }
    }
    else
    {
        menu.IsOpen = false;
    }
}

 

created 4 different contextmenus, 1 default and 3 other that depend on the cell where the user calls the contextmenu.

When I try setting this custom contextmenu in XAML as default for my GridView and as contextmenu for some cells using styles. I receive an InvalidOperationException stating that the given contextmenu is not a valid value for the ContextMenu property?

It worked with the regular ContextMenu, but when I change my custom ContextMenu to inherit from this class I cant call the function GetClickedElement<GridViewCell>()?

 

How can I solve this, I dont exactly understand why I get this exception with RadContextMenu and not with a regular ContextMenu.

Any help would be appreciated.

Regards,

 

Marcel

 

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 09 May 2016, 02:31 PM
Hello Marcel,

Can you please take a look at the following resources, as the recommended usage of RadContextMenu in conjunction with RadGridView is demonstrated in them.

-   RadContextMenu and RadGridView MVVM SDK Example.
-   RadContextMenu for RadGridView SDK Example.
-   Use RadContextMenu with a RadGridView help topic.

The SDK Examples can be reviewed through the SDK Samples Browser.

I hope this helps.

All the best,
Stefan X1
Telerik
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
Marcel
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or