I’m working on an Excel addin and have hit a roadblock.
I wish to update a combobox with the sheets in the Excel workbook. Currently I’m able to do this with a foreach loop. However, this is limited in the sense it only picks up added or subtracted sheets when I run it. My addin looks tacky with a “refresh sheets” button and I would like to avoid that if possible.
Ideally I’d be able to databind the worksheet object to the combobox so it’s updated on-the-fly without my intervention. However, my research has turned up that it doesn’t support that. I haven’t tried it, as I’m not in front of my dev computer until later, but I’m almost positive since it doesn’t inherit IList it won’t work as a datasource.
Has anyone done anything similar? I’d really like to get this thing working right.
Thank you!
The Excel.Application object has a
WorkbookNewSheetevent that fires when a new sheet is added. Unfortunately, it doesn’t seem to have an event that fires when a sheet is removed.You could put your combobox update code in the combobox’s
DropDownevent. It fires as the combobox is opening, and your code can update the combobox items before the list is visible.