我定义了一个类里面有一个属性type,我想初始化他的值并且值不止一个,type等于汽车和客车然后将这两个值添加到combox中去没有用数据的
------解决方案--------------------
//前台拖个comboBox1进去就可以了
- C# code
public partial class Form3 : Form { MyClass myClass = new MyClass(); public Form3() { InitializeComponent(); } private void Form3_Activated(object sender, EventArgs e) { myClass.Add("汽车"); myClass.Add("客车"); this.comboBox1.Items.AddRange(myClass.MyType.ToArray()); } } public class MyClass { private List<string> myType; public MyClass() { myType = new List<string>(); } public List<string> MyType { get { return this.myType; } set { this.myType = value; } } public void Add(string name) { if (!myType.Contains(name)) { myType.Add(name); } } public void Remove(string name) { if (myType.Contains(name)) { myType.Remove(name); } } }