Can you add an item to a combo box after initialization

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

Can you add an item to a combo box after initialization
 
David Pollak




Posts: 1
Joined: 2005-02-18
Can you add an item to a combo box other than in InitializeComponent? It seems that any time I try, an exception is fired when accessing ListIndex.
Posted 04 Oct, 2005 04:08:58 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi, David.

Yes, you can add items to a combo box at runtime using the Items property of the ADXCommandBarComboBox component.
Try the code below. Does it work for you?

private void AddinModule_AddinStartupComplete(object sender, System.EventArgs e)
{
if (adxCommandBarComboBox1.Items.Count == 0)
{
adxCommandBarComboBox1.Items.Add("Item 1");
adxCommandBarComboBox1.Items.Add("Item 2");
adxCommandBarComboBox1.Items.Add("Item 3");
adxCommandBarComboBox1.ListIndex = 1;
}
}
Posted 04 Oct, 2005 15:39:45 Top
Guest


Guest


Thanks! I was hoping to actually do it outside of the startup complete call (i.e in response to a button click on the toolbar). That's where I seem to get into trouble.
Posted 09 Oct, 2005 20:42:03 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi, David.

I don't get any errors when I add items in the Click event handler of a button:
private void adxCommandBarButton1_Click(object sender)
{
if (adxCommandBarComboBox1.Items.Count == 0)
{
adxCommandBarComboBox1.Items.Add("Item 1");
adxCommandBarComboBox1.Items.Add("Item 2");
adxCommandBarComboBox1.Items.Add("Item 3");
adxCommandBarComboBox1.ListIndex = 1;
}
}

What version of ADX do
Posted 10 Oct, 2005 05:25:31 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
David, what version of ADX do you use?
Posted 10 Oct, 2005 05:26:20 Top
Guest


Guest


The latest (2.2 I believe). I actually got an exception thrown when it tried to set the ListIndex variable
Posted 12 Oct, 2005 15:06:38 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi, David.

Could you send me the code? I will check it.
Posted 12 Oct, 2005 15:21:16 Top
Guest


Guest


Oddly, it is now working. It used to throw an exception in ItemInsertComplete (at the ListIndex call) from ADXCustomCommandBarComboBox.cs, but, now it does not (I reorganized some code so maybe something changed???). Thanks for the help!
Posted 13 Oct, 2005 14:40:25 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
No problem. Let me know if you face any difficulties with ADX.
I will help.
Posted 13 Oct, 2005 15:42:53 Top