Unplanned
Last Updated: 26 May 2020 12:06 by ADMIN
Clayton
Created on: 19 May 2020 12:38
Category: ContextMenu
Type: Feature Request
1
PopupManager: How can I stop the mouse scroll wheel from closing a radContextMenu?

I have a radGridView with a radContextmenu attached. When I open the radContextmenu via right clicking a form and then move the mouse scroll wheel radContextmenu is closed and the form behind the radContextmenu begins to scrolls. This does not happen with the standard contextMenu. 

I would like to avoid the mouse scroll wheel from closing the radContextmenu. The reason is in some radContextMenus I embed forms with scroll bars and so would like the user to use the mouse wheel to scroll these embedded forms (I can confirm that the scroll bars on these forms work fine while embedded in the context menu) rather than close the radContextmenu.

3 comments
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 26 May 2020 12:06

Hello, Clayton,   

The suggested solution shows how to remove a certain drop down from the PopupManager's default mouse handling by calling the PopupManager.Default.RemovePopup(drop down menu). However, it needs to be applied for each of the nested menu item's drop down.

Here is a sample code snippet for the illustrated screenshot:

        private void radGridView1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                PopupManager.Default.AddPopup(this.radContextMenu1.DropDown);
                PopupManager.Default.AddPopup(((RadMenuItem)this.radContextMenu1.Items[1]).DropDown);
                PopupManager.Default.CloseAll(RadPopupCloseReason.Mouse);  
            }
        }

        private void radContextMenu1_DropDownOpened(object sender, EventArgs e)
        {
            PopupManager.Default.RemovePopup(this.radContextMenu1.DropDown);
            ((RadMenuItem)this.radContextMenu1.Items[1]).DropDownOpened -= RadForm1_DropDownOpened;
            ((RadMenuItem)this.radContextMenu1.Items[1]).DropDownOpened += RadForm1_DropDownOpened;   
        }

        private void RadForm1_DropDownOpened(object sender, EventArgs e)
        {
            PopupManager.Default.RemovePopup(((RadMenuItem)this.radContextMenu1.Items[1]).DropDown);
        }

Note that this is just a  sample approach and it may not cover all possible cases. Feel free to modify and extend it in a way which suits your requirements best.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Clayton
Posted on: 20 May 2020 15:06

The workaround mentioned here does indeed prevent the radContextMenu itself from closing on moving the mouse wheel. However even after applying this it seems that any nested RadMenuItems that are opened are still closed on scrolling the mouse wheel?

Also, how would one apply the workaround mentioed here for the default radContextMenu for RadGridView?

ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 20 May 2020 07:37

Hello, Clayton,  

Indeed, when a RadContextMenu is shown and the user scrolls with the mouse wheel, the menu is closed and the grid rows are scrolled accordingly. This behavior is observed even with the default context menu for RadGridView.

All context menus in the Telerik UI for WinForms suite are managed by a PopupManager which internally uses an IMessageListener for the messages. The MouseWheel message is purposed to close all popups. You can disable this PopupManager to handle the context menu by using the following code: 

        public RadForm1()
        {
            InitializeComponent();

            this.radContextMenu1.DropDownOpened+=radContextMenu1_DropDownOpened;          
        }

        private void radContextMenu1_DropDownOpened(object sender, EventArgs e)
        {
            PopupManager.Default.RemovePopup(this.radContextMenu1.DropDown);
        }

However, it will disable the whole logic for closing the popup in the different scenarios. Hence, it would be necessary to close it programmatically, e.g. when you click the grid (see the attached gif file):

        public RadForm1()
        {
            InitializeComponent();

            this.radGridView1.ContextMenuOpening += radGridView1_ContextMenuOpening; 
            this.radContextMenu1.DropDownOpened += radContextMenu1_DropDownOpened;

            this.radGridView1.MouseClick += radGridView1_MouseClick;
        }

        private void radGridView1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                PopupManager.Default.AddPopup(this.radContextMenu1.DropDown);
                PopupManager.Default.CloseAll(RadPopupCloseReason.Mouse); 
                
            }
        }

        private void radContextMenu1_DropDownOpened(object sender, EventArgs e)
        {
            PopupManager.Default.RemovePopup(this.radContextMenu1.DropDown);
        }
          
        private void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
        {
            if (e.ContextMenuProvider is GridDataCellElement)
            {
                e.ContextMenu = this.radContextMenu1.DropDown; 
            }
        }

It sounds like a reasonable feature request to provide public API for the mouse input of the PopupManager. Thus, it would be possible to handle certain mouse messages, e.g. mouse wheel, and stop the context menus to be closed. 

I have logged it in our feedback portal by making this thread public  on your behalf. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

I have also updated your Telerik points.

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

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Attached Files: