none
BeforeRightClick-event on a chart is never fired RRS feed

  • Question

  • Hi all,

    I am creating an application level add-in for Excel and I am creating a chart object on a worksheet with something like this, to draw own shapes on the ChartArea:

    chart = worksheet.Controls.AddChart(selection, addonConfig.addonName);

    Now I want to modify the context menu of the chart, but I cannot listen to the BeforeRightClick-event of the object. When I attach 

    chart.BeforeRightClick += chart_BeforeRightClick;

    it is never fired. Strangly enough 

    chart.BeforeDoubleClick += chart_BeforeDoubleClick;

    is fired without any problems. But not the right click event.

    Any help? What I am doing wrong? Any help is appreciated.

    Kind regards,

    Jonas


    • Edited by J-F-X Wednesday, April 1, 2015 10:55 AM
    Wednesday, April 1, 2015 10:54 AM

Answers

  • Hi,

    For the chart in Excel, it has Chart Area and Plot Area, based on my test in Excel 2013, the BeforeRightClick event is used for the Plot Area, the BeforeDoubleClick event could be used for the Chart Area.

    Base on your code, I think you just add an empty chart without the Plot area, so the BeforeRightClick event won’t be fired.

    On the other hand, we need to base on the version of excel to custom the context menu.

    For more information, please refer to:

    # Customizing Context Menus in All Versions of Microsoft Excel

    https://msdn.microsoft.com/en-us/library/office/gg469862(v=office.14).aspx

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 2, 2015 6:16 AM
    Moderator

All replies

  • Hi,

    For the chart in Excel, it has Chart Area and Plot Area, based on my test in Excel 2013, the BeforeRightClick event is used for the Plot Area, the BeforeDoubleClick event could be used for the Chart Area.

    Base on your code, I think you just add an empty chart without the Plot area, so the BeforeRightClick event won’t be fired.

    On the other hand, we need to base on the version of excel to custom the context menu.

    For more information, please refer to:

    # Customizing Context Menus in All Versions of Microsoft Excel

    https://msdn.microsoft.com/en-us/library/office/gg469862(v=office.14).aspx

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 2, 2015 6:16 AM
    Moderator
  • Hi Starain,

    indeed, if I add a series to the series collection, the BeforeRightClick event is fired. Unfortunately I want to draw those shapes by myself (as I want to implement a custom chart type).

    So can I initialize the plot area by myself somehow? The series collection item throws in so many unwanted shapes ....

    Thank you so much for your help so far!

    Jonas

    Thursday, April 2, 2015 7:30 AM
  • Hi,

    A simple sample to add chart with data:

     Excel.Worksheet worksheet = this.Application.Worksheets[1];
                var sheetVSTO = Globals.Factory.GetVstoObject(worksheet);
                worksheet.Range["A1", "A5"].Value2 = 22;
                worksheet.Range["B1", "B5"].Value2 = 55;
                Microsoft.Office.Tools.Excel.Chart chart1 =
            sheetVSTO.Controls.AddChart(worksheet.Range["D2", "H12"],
            "chart1");
                chart1.SetSourceData(worksheet.Range["A1", "B5"],
                    Excel.XlRowCol.xlColumns);
                chart1.ChartType = Excel.XlChartType.xl3DColumn;
    
                chart1.BeforeRightClick +=
                    new Excel.ChartEvents_BeforeRightClickEventHandler(
                    chart1_BeforeRightClick);

    On the other hand, if you have the issues that don't redirect related to the original issue, I suggest that you could open the new threads. This will make answer searching in the forum easier and be beneficial to other community members as well.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 2, 2015 8:52 AM
    Moderator