none
VSTO: Inserting UserControl into Chart Sheet RRS feed

  • Question

  • Hi,

    I would like to insert a UserControl into a chart sheet. The only function I have found that can insert a UserControl is the AddControl function which requires a Selection to insert a Control. I have tried to use the following code but it does not work:

    Microsoft.Office.Interop.Excel.Chart ch = (Excel.Chart)wb.Sheets[1];
    ch.Activate();
    ch.Select();
    ch.ChartArea.Select();
    ch.Shapes.SelectAll();
    
    Excel.Range selection = Globals.ThisAddIn.Application.Selection as Excel.Range;
    worksheet.Controls.AddControl(new UserControl2(), selection, "fnis");

    Wednesday, January 20, 2016 11:02 AM

All replies

  • >>>I would like to insert a UserControl into a chart sheet. The only function I have found that can insert a UserControl is the AddControl function which requires a Selection to insert a Control. I have tried to use the following code but it does not work:<<<

    According to your description, I have created one Document Level Excel Addin to try to add UserControl into ChartSheet manually, unfortunately, I can't, you could refer to result:

    but if you add UserControl into WorkSheet manually, you could add successfully, you could refer to result:



    Although a ChartSheet host item is a worksheet in Excel, you cannot add any controls to the chart sheet. If you want to have other controls on a worksheet with a chart, do not use a chart sheet.

    Instead, you can place a chart as an embedded object on a worksheet by using the Chart host control.

    For more information, click here to refer about ChartSheet Host Item

    Thursday, January 21, 2016 9:47 AM