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

ContextMenuOpening event doesnt fire up when right click on the GridView

6 Answers 381 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dean Marriott
Top achievements
Rank 1
Dean Marriott asked on 26 Nov 2012, 06:11 AM
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?

6 Answers, 1 is accepted

Sort by
0
Anton
Telerik team
answered on 26 Nov 2012, 01:55 PM
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.
0
Dean Marriott
Top achievements
Rank 1
answered on 26 Nov 2012, 10:58 PM
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!
0
Anton
Telerik team
answered on 29 Nov 2012, 03:05 PM
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.
0
Helen
Top achievements
Rank 2
answered on 27 Feb 2013, 12:45 AM
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
0
Anton
Telerik team
answered on 27 Feb 2013, 02:33 PM
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.
0
Helen
Top achievements
Rank 2
answered on 27 Feb 2013, 06:53 PM
Perfect!

Thanks Anton!
Tags
GridView
Asked by
Dean Marriott
Top achievements
Rank 1
Answers by
Anton
Telerik team
Dean Marriott
Top achievements
Rank 1
Helen
Top achievements
Rank 2
Share this question
or