我创建了一个名为 ComboBoxitem 的自己的类,它有两个道具:值和文本。
public class ComboBoxItem
{
public string Value;
public string Text;
public ComboBoxItem(string val, string text)
{
Value = val;
Text = text;
}
public override string ToString()
{
return Text;
}
}
现在我想每次都向组合框项添加一个值和一个文本
像这样的东西:
public ComboBoxItem busstops;
private void Form1_Load(object sender, EventArgs e)
{
lblText.Text = "Timetable Bushours for " + "New Bridge Street-St Dominics";
busstops = new ComboBoxItem("410000015503", "New Bridge Street-St Dominics");
busstops = new ComboBoxItem("410000015552", "Bothal Street (N-Bound), Byker ");
/* comboBox1.Items.Add(new ComboBoxItem ("410000015503", "New Bridge Street-St Dominics"));
comboBox1.Items.Add(new ComboBoxItem("410000015552", "Bothal Street (N-Bound), Byker "));*/
comboBox1.Items.Add(busstops);
}
但问题是只添加了最后一项(正常,因为我总是说新的 ComboboxItem)但是如何更改他总是可以添加新的组合框项的代码?
谢谢!