简体   繁体   English

没有添加到组合框的项目

[英]Items not adding to ComboBox

I just started learning C# today. 我今天才开始学习C#。 And I proceed already in creating GUI since some syntax are just like Java. 我已经开始创建GUI,因为某些语法就像Java。 Here's what I did so far: 这是我到目前为止所做的:

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);
    }
}

But it's not adding to the ComboBox. 但这并没有添加到ComboBox中。 What am I doing wrong ? 我究竟做错了什么 ?

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 never seems to be changing. SelectedIndexChanged似乎从未改变过。 Plus any time you change the index, you'll re-add all the items again. 另外,只要您更改索引,便会再次重新添加所有项目。 Form_Load would be better. Form_Load会更好。 Load it once....done. 加载一次。...完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM