"Object reference not set to an instance of an object" when dynamically adding Buttons to Ribbon

Add-in Express™ Support Service
That's what is more important than anything else

"Object reference not set to an instance of an object" when dynamically adding Buttons to Ribbon
 
Tobias Böhm




Posts: 73
Joined: 2009-07-06
I try to dynamically add ADXRibbonButtons to an ADXRibbonGroup. I do this from inside the OnRibbonBeforeCre ate event. The creation works find but after the OnRibbonBeforeCre ate event the OnError event gets fired with following exception:

"Object reference not set to an instance of an object.

at AddinExpress.MSO.ADXRibbonButton.GetAttributes()
at AddinExpress.MSO.ADXRibbonCustomControl.AddinExpress.MSO.IADXRibbonComponent.get_Attributes()
at AddinExpress.MSO.ADXAddinModule.ProcessChildren(XmlTextWriter xmlData, IADXRibbonComponent ribbonElement, String ribbonID)
at AddinExpress.MSO.ADXAddinModule.ProcessChildren(XmlTextWriter xmlData, IADXRibbonComponent ribbonElement, String ribbonID)
at AddinExpress.MSO.ADXAddinModule.ProcessChildren(XmlTextWriter xmlData, IADXRibbonComponent ribbonElement, String ribbonID)
at AddinExpress.MSO.ADXAddinModule.AddinExpress.MSO.IRibbonExtensibility.GetCustomUI(String RibbonID)"

I use following code inside a loop to add the buttons

          
                    AddinExpress.MSO.ADXRibbonButton r = new AddinExpress.MSO.ADXRibbonButton
                    {
                        Id = "ColorButtonID_" + c.ToString(),
                        Tag = c.ToArgb(),
                        Caption = string.Empty,
                        ScreenTip = c.ToString(),
                        ImageList = imageList,
                        Image = index++,
                        Enabled = true
                    };

                     adxRibbonGroup.Controls.Add(r);


Thanks in advance,
Tobias
Posted 28 Jan, 2010 10:18:15 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Hi Tobias,

Try using a non-empty string in the Caption property.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Jan, 2010 11:52:40 Top
Tobias Böhm




Posts: 73
Joined: 2009-07-06
Sorry, that didn't work either.
Do you have an example about how to add buttons at run-time?

Tobias
Posted 28 Jan, 2010 11:57:09 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Tobias.

Do you pass the 'this.components' field as a parameter to the ADXRibbonButton constructor?
E.g.
this.myButton = new AddinExpress.MSO.ADXRibbonButton(this.components);
Posted 28 Jan, 2010 12:01:59 Top
Tobias Böhm




Posts: 73
Joined: 2009-07-06
Thanks, this was it.
Plus my variable that I assigned to the Id-Property hat a whitespace in it. Not a good idea. That caused the Ribbon to temporarily disappear (independent from my other open issue, but could it have something to do with it?)

Thanks
Posted 28 Jan, 2010 12:30:26 Top