GrapeCity / ComponentOne-MAUI-Samples

3 stars 4 forks source link

Implement a context Menu for flexgrid #7

Open enkaradag opened 8 months ago

enkaradag commented 8 months ago

Hi,

Right click context menu is useful for desktop platforms, such as winui and maccatalyst (and also android when it is used with an ext. screen, keyboard and a mouse)

I have to catch which cell is right clicked. Some items in the popup menu should be hidden according to the cell that is right clicked. So i have to catch cell info and reorganize the popup items before it is shown.

What is the best practice for adding a context menu for flexgrid?

Regards

Ender

enkaradag commented 8 months ago

Setting flyoutbase for grid on CellTapped runs before popup is shown. That fits my need for now for winui

        MenuFlyout PopupMenu = new MenuFlyout();
        MenuFlyoutItem PopupItem1 = new MenuFlyoutItem() { Text = "RowOption1" };
        MenuFlyoutItem PopupItem2 = new MenuFlyoutItem() { Text = "RowOption2" };
        PopupMenu.Add(PopupItem1);
        PopupMenu.Add(PopupItem2);

        MenuFlyout PopupMenuHeader = new MenuFlyout();
        MenuFlyoutItem PopupItemHeader1 = new MenuFlyoutItem() { Text = "ColumnOption1" };
        MenuFlyoutItem PopupItemHeader2 = new MenuFlyoutItem() { Text = "ColumnOption2" };
        PopupMenuHeader.Add(PopupItemHeader1);
        PopupMenuHeader.Add(PopupItemHeader2);

        grid.CellTapped += async (s, e) =>
        {
            if (e.CellType == GridCellType.ColumnHeader)
            {
                FlyoutBase.SetContextFlyout(grid, PopupMenuHeader);
                Debug.WriteLine("ColumnHeaderTapped");
            }
            else
            {
                FlyoutBase.SetContextFlyout(grid, PopupMenu);
                Debug.WriteLine("CellTapped");
            }
        };

flexgrid_contextmenu

I tested it for maccatalyst also, right clicking a row does not select it. For correct right click in mac, row (or column header) must be left clicked at first, then right click to show the correct popup. Do we have a workaround for this?

flexgrid_contextmenu_mac

And last, i think there's no options for android for right click context menu. It's ok

Regards