Check if context menu is displayed

4 posts, 0 answers
  1. Kim
    Kim avatar
    47 posts
    Member since:
    Jul 2013

    Posted 26 Jul 2013 Link to this post

    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.


  2. Dimitar
    Admin
    Dimitar avatar
    2881 posts

    Posted 31 Jul 2013 Link to this post

    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 >>
  3. AD
    AD avatar
    7 posts
    Member since:
    Jul 2008

    Posted 30 Nov 2019 in reply to Dimitar Link to this post

    How can you check from a thread within a Form if the contextmenu of a radgridview is diplayed or if it is hidden?
  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3719 posts

    Posted 02 Dec 2019 Link to this post

    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.
Back to Top