RadGridView Context Menus -- How to tell which Context Menu is showing in the ContextMenuOpening event?

1 Answer 14 Views
ContextMenu GridView
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Roger asked on 03 Jun 2022, 08:55 PM

The radgrid view has many different context menus it can show depending on what row you are on.

 

Header

Column Header

Column Filter Row (Contains, Begins With ....)

FilterRow (Type and highlights Yellow if found in Grid Results)

DataRow 

 

private void gvResults_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
        {

     // How to tell which row I am in so I can change if needed the context menu?

}

 

// This is how I can tell if it is a Data Row

GridDataCellElement dataCell = e.ContextMenuProvider as GridDataCellElement;
            if (dataCell == null)
                return;

 

// What about the others? 

//How can I tell  (Column Header, Column Filter, Row Filter etc.)

 

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Jun 2022, 09:04 AM
Hello, Roger, 

The ContextMenuOpeningEventArgs.ContextMenuProvider property gives you access to the cell element for which the menu is opening. The following code snippet demonstrates a sample approach how to distinguish the cells:
        private void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
        { 
            GridHeaderCellElement headerCell = e.ContextMenuProvider as GridHeaderCellElement;
            GridFilterCellElement filterCell = e.ContextMenuProvider as GridFilterCellElement;
            GridDataCellElement dataCell = e.ContextMenuProvider as GridDataCellElement;
            if (headerCell != null)
            {
                Console.WriteLine("header cell");
            }
            else if (filterCell != null)
            { 
                Console.WriteLine("filter cell"); 
            }
            else if (dataCell != null)
            {
                Console.WriteLine("data cell");
            }
        }

Please have in mind that for the filter cell you may obtain two different context menus - when the user clicks the filter button and when the user right-clicks the filter cell itself. However, in both cases the ContextMenuProvider is the GridFilterCellElement. You can distinguish the two situations by the menu items inside the context menu.

In case you need to detect another element, you can simply print the ContextMenuProvider and see what is the related element.

I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ContextMenu GridView
Asked by
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or