ContextMenuOpening event doesnt fire up when right click on the GridView

7 posts, 0 answers
  1. Dean Marriott
    Dean Marriott avatar
    17 posts
    Member since:
    May 2007

    Posted 26 Nov 2012 Link to this post

    Hi guys,
    This is how I use this event. It worked fine in Q3 2011.
    this.radGridView1.ContextMenuOpening += new Telerik.WinControls.UI.ContextMenuOpeningEventHandler(this.radGridView1_ContextMenuOpening);

    private void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
           {
              //implementation code here
                  e.ContextMenu = radContextMenu1.DropDown;
             
           }
    Since I started using Q3/2012, this event doesnt seem to work anymore. Any suggestion?
  2. Anton
    Admin
    Anton avatar
    167 posts

    Posted 26 Nov 2012 Link to this post

    Hello Dean,

    Thank you for writing.

    I tried to reproduce the experienced issue locally with version Q3/2012(2012.3.1017) but everything is working as expected on my end. There is sample demo project attached which I have used in my tests. Could you please take a look at it and modify it on a way to replicate the undesired behavior. This will allow me to investigate it and provide you with further support.

    Thank you in advance for your collaboration. I am looking forward to your reply.

    Kind regards,
    Anton
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dean Marriott
    Dean Marriott avatar
    17 posts
    Member since:
    May 2007

    Posted 26 Nov 2012 Link to this post

    Hi Anton,

    Thank you for the quick reply.
    It seems like something in my code that affect the GridView's default behaviour. I tried your project and everything seems to work fine.
    I will need more time to look into this issue.
    Updated: found the line that cause issue
    this.radGridViewEmployees.MasterTemplate.AllowCellContextMenu = false;
    Somehow this worked in old version and now it doesnt. Change it to true and works again!
  5. Anton
    Admin
    Anton avatar
    167 posts

    Posted 29 Nov 2012 Link to this post

    Hi Dean,

    Thank you for writing back.

    I am glad to hear that everything is OK now. Feel free to ask if you have any additional questions.

    Kind regards,
    Anton
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  6. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 26 Feb 2013 Link to this post

    I am finding a lot of my grid context menus are getting screwed up with the latest version.

    Can you tell me how to prevent the context menu from displaying if the user right-clicks on the column headers or the empty new row?

    Thanks

    Helen
  7. Anton
    Admin
    Anton avatar
    167 posts

    Posted 27 Feb 2013 Link to this post

    Hi Helen,

    Thank you for writing.

    In order to prevent the context menu to showing on specific areas you should subscribe to ContextMenuOpening event and create your custom logic. For example:
    void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
    {
        if (e.ContextMenuProvider is GridDataCellElement)
        {
            GridDataCellElement cell = e.ContextMenuProvider as GridDataCellElement;
            e.Cancel = true;
            foreach (GridViewCellInfo item in cell.RowInfo.Cells)
            {
                if (item.Value != null)
                {
                    e.Cancel = false;
                }
            }
        }
     
        if (e.ContextMenuProvider is GridHeaderCellElement)
        {
            e.Cancel = true;
        }
    }

    I hope this helps. If you have further questions, feel free to write back.

    All the best,
    Anton
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  8. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 27 Feb 2013 Link to this post

    Perfect!

    Thanks Anton!
Back to Top
UI for WinForms is Visual Studio 2017 Ready