简体   繁体   中英

VSTO Ribbon1 is null

It's the first time I using VSTO for Excel-AddIn,I want to populate the combox items in the Ribbon_Load function.But when I using such code:

Globals.Ribbons.Ribbon1.Combox1.Items.Add(Items);

It can not work,when I debug the code,it's value is display as " Globals.Ribbons.Ribbon1 is null " in the monitoring panel. And there is some initial init code about Ribbon1 below:

partial class ThisRibbonCollection
{
    internal GZMenu Ribbon1
    {
        get { return this.GetRibbon<GZMenu>(); }
    }
}

Please give me some help!

From the code you show us I'm assuming you're using the Ribbon Designer...

You can populate the items either in through the Properties window, the "Items" entry (static list) or dynamically using code.

If you want to use code, you should be working in the Ribbon class. (Note: it looks like you've been modifying what VSTO has generated. If you're having problems I highly recommend you stick to what VSTO generates, to begin with, until you get things working.)

I have the code in the class initializer, but it also works in Ribbon1.Load :

public partial class Ribbon1 : OfficeRibbon
{
    object missing = System.Type.Missing;
    static internal RibbonButton btnTest = null;
    static internal Office.IRibbonUI rUI = null;

    public Ribbon1()
    {
        InitializeComponent();
        RibbonDropDownItem ddItem1 = new RibbonDropDownItem();
        ddItem1.Label = "Item added at runtime";
        ddList.Items.Add(ddItem1);

        RibbonDropDownItem ddItem2 = new RibbonDropDownItem();
        ddItem2.Label = "Second item added at runtime";
        ddList.Items.Add(ddItem2);
        ddList.SelectedItemIndex = 1;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM