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

Check if context menu is displayed

3 Answers 872 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kim
Top achievements
Rank 1
Kim asked on 26 Jul 2013, 11:37 PM
Hi again!

How can I check if context menu is displayed?

I have a mouse_click event and if the user right clicks off a row (into white space) I display a custom popup. However, when the user right clicks on a row, the context menu pops up and then my menu pops up over top.

What i need to do is to determine whether the user right clicked on a row, or on white space so i can avoid showing my popup if they right clicked on a row.  

Thanks.


3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 31 Jul 2013, 04:54 PM
Hello Kim,

Thank you for writing.

You can use the following mouse click event which will display the custom context menu only if you are not clicking on cell:
void radGridView1_MouseClick(object sender, MouseEventArgs e)
{
    GridDataCellElement cell = radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
 
    if (e.Button == System.Windows.Forms.MouseButtons.Right && cell == null)
    {
        Point p = (sender as Control).PointToScreen(e.Location);
        contextMenu.Show(p.X, p.Y);
    }
}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
AD
Top achievements
Rank 1
answered on 30 Nov 2019, 11:12 AM
How can you check from a thread within a Form if the contextmenu of a radgridview is diplayed or if it is hidden?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Dec 2019, 12:44 PM
Hello, Apostolos,

The default context menu of RadGridView is displayed when you right-click a grid's cell. In the ContextMenuOpening event you can subscribe to the ContextMenu.DropDownOpened and ContextMenu.DropDownClosed events in order to detect when the context menu is opened/closed. 
        public RadForm1()
        {
            InitializeComponent();

            this.radGridView1.ContextMenuOpening += radGridView1_ContextMenuOpening;
        }

        private void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
        {
            e.ContextMenu.DropDownOpened -= ContextMenu_DropDownOpened;
            e.ContextMenu.DropDownOpened += ContextMenu_DropDownOpened;

            e.ContextMenu.DropDownClosed -= ContextMenu_DropDownClosed;
            e.ContextMenu.DropDownClosed += ContextMenu_DropDownClosed;
        }
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

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Kim
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
AD
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or