每次使用时都将“表单1”打印到组合框中c#

时间:2017-03-22 22:35:14

标签: c#

每次我使用组合框添加记录时,它会在组合框列表的底部添加“表单1”,除了与iCount有关之外,我似乎无法找到原因?

我是初学者,请帮忙

//initialise array of module codes
string[] sMonths = new string[] { "01", "02", "03", "04", "05",
                               "06", "07", "08", "09", "10", "11", "12" };

//initialise combo box from sModules array
for (int iCount = 0; iCount < sMonths.Length; iCount++)
{
    cboMonth.Items.Add(sMonths[iCount]);

}

进一步观察后,我认为错误发生在这里......

using (StreamWriter sw = new StreamWriter("EVENTS.TXT", true))
        {

            sw.WriteLine(txtEvent.Text);

            sw.WriteLine(txtVenue.Text);

            sw.WriteLine(cboMonth.Items.Add(Text));

            sw.WriteLine(lstActivity.SelectedItem);



            if (rdoRange1.Checked == true)
            {
                sw.WriteLine(rdoRange1.Text);
            }
            else if (rdoRange2.Checked == true)
            {
                sw.WriteLine(rdoRange2.Text);
            }
            else if (rdoRange3.Checked == true)
            {
                sw.WriteLine(rdoRange3.Text);
            }
            else
            {
                sw.WriteLine(rdoRange4.Text);
            }

            sw.Close();
        }

1 个答案:

答案 0 :(得分:1)

删除该行:

sw.WriteLine(cboMonth.Items.Add(Text));

它为你的组合框添加了一个额外的项目,很可能就是“&#39;形式1&#39;