未添加到 ComboBox 的项目
Items not adding to ComboBox
我今天才开始学习C#。我已经开始创建 GUI,因为一些语法就像 Java。
这是我到目前为止所做的:
Click on the ComboBox in , Design tab. Then it directed me a method.
Inside the method, here is my code:
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
int days = 31;
for (int i = 1; i <= days; i++)
{
this.dayComboBox.Items.Add(i);
}
}
但它没有添加到 ComboBox。我究竟做错了什么 ?
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
//some other code
}
private void Form_Load(object sender, EventArgs e)
{
int days = 31;
for (int i = 1; i <= days; i++)
{
this.dayComboBox.Items.Add(i);
}
}
SelectedIndexChanged
似乎永远不会改变。另外,每当您更改索引时,您都会再次重新添加所有项目。 Form_Load 会更好。加载一次....完成。
我今天才开始学习C#。我已经开始创建 GUI,因为一些语法就像 Java。 这是我到目前为止所做的:
Click on the ComboBox in , Design tab. Then it directed me a method. Inside the method, here is my code:
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
int days = 31;
for (int i = 1; i <= days; i++)
{
this.dayComboBox.Items.Add(i);
}
}
但它没有添加到 ComboBox。我究竟做错了什么 ?
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
//some other code
}
private void Form_Load(object sender, EventArgs e)
{
int days = 31;
for (int i = 1; i <= days; i++)
{
this.dayComboBox.Items.Add(i);
}
}
SelectedIndexChanged
似乎永远不会改变。另外,每当您更改索引时,您都会再次重新添加所有项目。 Form_Load 会更好。加载一次....完成。