I'm trying to implement a custom context menu for a WinForms.ReportViewer control. I can get my custom menu to show if the user right clicks in the "toolbar" area of the ReportViewer control at the very top of the control, but when clicking in the main part of the control that displays the actual report data, the default context menu that comes with the ReportViewer displays. Is there a way to get my context menu to replace the default?
I've searched through the controls collection of the ReportViewer, none of them are a ContextMenuStrip. If it matters, the ReportViewer control version is 15.0.0.0.
private void CreateContextMenu()
{
ContextMenuStrip menuStrip = new ContextMenuStrip();
ToolStripMenuItem menuItem = new ToolStripMenuItem("Exit");
menuItem.Click += new EventHandler(MenuItem_Click);
menuItem.Name = "Exit";
menuStrip.Items.Add(menuItem);
// This makes no difference.
//this.reportViewer1.ContextMenu = null;
this.reportViewer1.ContextMenuStrip = menuStrip;
}
private void MenuItem_Click(object sender, EventArgs e)
{
ToolStripItem menuItem = (ToolStripItem)sender;
if(menuItem.Name == "Exit")
{
Application.Exit();
}
}