How do I add items at runtime to an ADXBackstageComboBox?

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

How do I add items at runtime to an ADXBackstageComboBox?
(and/or ADXBackstageDropDown) 
aweber




Posts: 72
Joined: 2013-11-21
I expected the control to have an Add() method for strings, but it doesn't.

It has an Items collection, which is apparently a ReadOnly ADXRibbonControlCollection, so I can't runtime add items to that either?

I started to look through some of the examples, but didn't find anything yet.

Thanks for any tips/tricks.

-AJ
Posted 22 Nov, 2013 15:14:52 Top
Andrei Smolin


Add-in Express team


Posts: 14981
Joined: 2006-05-11
Hello,

Office Ribbon is a static thing and it does allow modifying creating controls at run time only for one control: this is ADXRibbonMenu having ADXRibbonMenu.Dynamic = true. All Other controls cannot be populated at run time.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Nov, 2013 03:36:07 Top
aweber




Posts: 72
Joined: 2013-11-21
I don't want to modify the Office Ribbon at runtime.

I would like to add items to a combobox displayed on my BackStage form at runtime. This would seem to be a pretty reasonable request. There are comboboxes on the default, office backstage forms that are populated at runtime, and I can remember adding items to comboboxes as far back as VB5.
Posted 25 Nov, 2013 07:25:43 Top
Andrei Smolin


Add-in Express team


Posts: 14981
Joined: 2006-05-11
This isn't about populating a System.Windows.Forms.ComboBox control (which is okay, of course). You talk about populating a BackstageView combobox, and this is an absolutely different story.

Add-in Express generates the OnDibbonBeforeCreate and OnRibbonBeforeLoad events. These events are used to supply the Office application with the XML markup that Add-in Express components create behind the scene. The Backstage View is part of the markup as well as all Ribbon controls. All of them are static from birth except for the dynamic Ribbon menu control.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Nov, 2013 07:45:48 Top
Andrei Smolin


Add-in Express team


Posts: 14981
Joined: 2006-05-11
Hmm, I may be mistaken. I'll create a test project and inform you about my results in a couple of hours.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Nov, 2013 07:51:03 Top
Andrei Smolin


Add-in Express team


Posts: 14981
Joined: 2006-05-11
Thank you for making me think about this! You were right:

int counter = 0;
private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed) {
    ADXBackstageItem newItem = new ADXBackstageItem();
    newItem.Id = "id" + counter.ToString();
    newItem.Caption = DateTime.Now.ToString();
    object result = this.adxBackstageComboBox1.Items.Add(newItem);
    counter++;
    ribbon.InvalidateControl(adxBackstageComboBox1.Id);
}

IRibbonUI ribbon = null;
private void AddinModule_OnRibbonLoaded(object sender, IRibbonUI ribbon) {
    this.ribbon = ribbon;
}


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Nov, 2013 09:46:11 Top
aweber




Posts: 72
Joined: 2013-11-21
I couldn't get this to work, but didn't get any exceptions thrown trying either...

Note, that I'm trying to add the items to an ADXBackstageComboBox on an ADXBackstageView (not a Ribbon).

I have set the following within a method in the OnShow for the adxBackstageView1 control/object:

if (adxBScmbNames.Items.Count == 0)
   {
     List<string> names = getListFromXML(getXMLText(),"name");

     foreach (string name in names) {
            ADXBackstageLabelControl lbl = new ADXBackstageLabelControl();
            lbl.Id = "id" + name;
            lbl.Caption = name;
            adxBScmbMatterName.Items.Add(lbl);
     }
     adxBScmbName.Invalidate();
     log.Debug("Finished loading " + adxBScmbName.Items.Count + " names");
   }


Pretty simple. Throws no exceptions, but if I put a breakpoint on the Invalidate call, the Items.Count is still 0 (and it tried to add 107 items).

-AJ
Posted 26 Nov, 2013 12:52:28 Top
Andrei Smolin


Add-in Express team


Posts: 14981
Joined: 2006-05-11
Hello AJ,

You need to replace ADXBackstageLabelControl with ADXBackstageItem.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Nov, 2013 00:21:15 Top
aweber




Posts: 72
Joined: 2013-11-21
Ah, that worked great!

One more question about the ADXBackstageComboBox:
What would be the procedure/pseudo-code to make the combobox fill the current BackstageView Column horizontally, but NOT expand due to some obscenely long item-caption.

If I set the combobox's Expand = Horizontal, it fills the column perfectly...but if I add a value at runtime that is too long, the first time I click to open the combobox, it further expands the control, expanding the entire column AND the entire window to fit the largest value.

I tried setting Expand = Horizontal at design-time, then setting it to "Neither" after filling the values at runtime, but this had no effect.

Thanks again,
AJ
Posted 27 Nov, 2013 07:46:07 Top
Andrei Smolin


Add-in Express team


Posts: 14981
Joined: 2006-05-11
AJ,

You have only two ways to influence the size of a backstage combo: the Expand and the SizeString property.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Nov, 2013 10:08:26 Top