Adding separate context menus for each hierarchical grid.

0 Answers 56 Views
ContextMenu GridView
Dave
Top achievements
Rank 2
Iron
Iron
Iron
Dave asked on 29 Oct 2024, 02:37 AM

Is there a simple way to enable a different context menu for each level of a hierarchical grid?   

I only see ContextMenuOpening for the grid as a whole and don't see a way to determine which sub grid was selected which didn't involve checking column names. The templates only seem they are there to support layout.

Attached is a sample app.

Thanks,

_Dave

Dave
Top achievements
Rank 2
Iron
Iron
Iron
commented on 31 Oct 2024, 02:40 AM

Figured it out:


        private void Grid_MouseDown(object? sender, MouseEventArgs e)
        {
            if (Grid.ElementTree.GetElementAtPoint(e.Location) is GridDataCellElement cell && e.Button == MouseButtons.Right)
            {
                if (cell.RowInfo.ViewTemplate.Caption == "OrderInfo")
                {
                    ordersContextMenu?.Show(Grid, e.Location);
                }
                else if (cell.RowInfo.ViewTemplate.Caption == "Items")
                {
                    itemsContextMenu?.Show(Grid, e.Location);
                }
            }
        }

        private void Grid_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
        {
            e.Cancel = true;
        }

Nadya | Tech Support Engineer
Telerik team
commented on 31 Oct 2024, 12:08 PM

Hello, Dave,

I am really glad to hear that you managed to find a solution for achieving your requirement. Your solution for checking the caption of each grid view template before showing the context menu seems absolutely right to me. More information is available in the context menu section in our RadGridView documentation here.

If you have any other difficulties, do not hesitate to contact us.

No answers yet. Maybe you can help?

Tags
ContextMenu GridView
Asked by
Dave
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or