开发者

Can't populate RibbonMenu

I need to populate a RibbonMenu control at run-time, with some data from a database.

I take my offset in: http://msdn.microsoft.com/en-us/library/microsoft.office.tools.ribbon.ribbonmenu(v=vs.90).aspx

with the code:

private void PopulateCustomerMenu()
{
    // Add two sub-menus to EmployeeMenu and populate each sub-menu
    // First sub-menu
    RibbonMenu subMenu1 = new RibbonMenu(); //new RibbonMenu(); is underlined red
    subMenu1.Dynamic = true;
    subMenu1.Label = "A - M";
    subMenu1.Items.Add(new Ribbo开发者_JAVA技巧nToggleButton()); //new RibbonToggleButton() is as well
    ((RibbonToggleButton)subMenu1.Items.Last()).Label = "Hall, Don";
    subMenu1.Items.Add(new RibbonToggleButton()); //new RibbonToggleButton() is as well
    ((RibbonToggleButton)subMenu1.Items.Last()).Label = "Valdez, Rachel";
    CustomerMenu.Items.Add(subMenu1);

    // Second sub-menu
    RibbonMenu subMenu2 = new RibbonMenu(); //new RibbonMenu(); is as well
    subMenu2.Dynamic = true;
    subMenu2.Label = "N - Z";
    subMenu2.Items.Add(new RibbonToggleButton()); //new RibbonToggleButton() is as well
    ((RibbonToggleButton)subMenu2.Items.Last()).Label = "Robinson, Alex";
    CustomerMenu.Items.Add(subMenu2);
}

The only thing I get is Visual Studio saying "Error 1 Cannot create an instance of the abstract class or interface 'Microsoft.Office.Tools.Ribbon.RibbonMenu' C:\Users\Christoffer\Documents\Visual Studio 2010\Projects\OutlookAddIn2\OutlookAddIn2\Ribbon1.cs 80 35 OutlookAddIn2"

I have been stuck for the last 15 hours, so I'm open for anything.... Any ideas?


Interestingly enough there is an interface and there is a class both with the same name that are in different dll's. If you look at the documentation page here you see the following information about the loaction of the interface:

Namespace: Microsoft.Office.Tools.Ribbon

Assembly: Microsoft.Office.Tools.Common (in Microsoft.Office.Tools.Common.dll)

On the page you linked to you have:

Namespace: Microsoft.Office.Tools.Ribbon

Assembly: Microsoft.Office.Tools.Common.v9.0 (in Microsoft.Office.Tools.Common.v9.0.dll)

The one you linked to is from the Visual Studio 2007 edition (hence the v=vs90 in the link. If you are trying to use that version then make sure the proper dll (Microsoft.Office.Tools.Common.v9.0.dll) is being referenced by your project and not the new dll (Microsoft.Office.Tools.Common.dll)

If you want to use the new dll then in order to create menu or menu items you must get an instance of the RibbonFactory based upon where you are building the Ribbon. For example if you were trying to add a Ribbon menu to Word you'd call Globals.Factory.GetRibbonFactory() and then use the factory returned by this call to create your Ribbon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜