C# excel addin - Accessing Controls
I am working on an addin for excel 2010 using C#. I have an existing worksheet that 开发者_开发百科has some controls in it, namely a ComboBox. I am trying to write some code that will place a certain value in the combo box's text property, but I am having a hard time getting access to the control to do so.
The combo box is named 'ComboBox1' but if I try something like...
var combo = Controls["ComboBox1"];
I get an ArgumentOutOfRangeException.
Exploratory approaches to finding out what I am supposed to be doing aren't really providing useful information either. For example, if were to write;
MessageBox.Show(Controls[0].GetType())
The displayed message is 'NamedRangeImpl' which doesn't seem like a control at all. So my question is, how do I get access to the controls that are on my worksheet from my code?
I'm not exactly sure about the problem but I've made addins for word and if its like windows forms this should work nicely.
foreach (Control c in Controls)
if (c.Name == "comboBox1") {
ComboBox box = (ComboBox)c;
box.Items.Add("Thing added");
}
精彩评论