I have an array of objects that I'm trying to add to the Items collection of a combo box control using the AddRange method. The method takes an object[] but when I pass it the name of the array which has been intialized with some values, it complains:
The best overloaded method match for 'System.Windows.Forms.ComboBox.ObjectCollection.AddRange(object[])' has some invalid arguments.
The class defining the objects in my array is very simple:
public class Action { public string name; public int value; public override string ToString() { return name; } }
and my array is declared such:
public Action[] actions = new Action[] {
new Action() { name = "foo", value = 1 },
new Action() { name = "bar", value = 2 },
new Action() { name = "foobar", value = 3 }
};
this is where I try to call AddRange:
combobox1.Items.AddRange(actions);
and that's the line that it's complaining about - is there some step I'm missing to be able to do this? it works fine when I'm just adding a simple string[]