winform程序中comboBox控件问题。寝室号:      [comboBox控件]寝室号是: 101-149,201-249,.....501-549。
一起五楼。comboBox编辑项可以每行添加一个数,
我想用循环来写,怎样写啊?            for (int i = 1; i < 6; i++)
            {
                for (int j = 1; j < 50; j++)
                {
                    string i1 = Convert.ToString(i);
                    string j1 = Convert.ToString(j);
                    if (j < 10)
                    {
                        j1 ="0"+j1;
                        Console.WriteLine(i1 + j1);
                    }
                    else
                    {
                        Console.WriteLine(i1 + j1);
                    }
                }
            }for循环又放到那里呢?

解决方案 »

  1.   

     for (int i = 1; i < 6; i++) 
                { 
                    for (int j = 1; j < 50; j++) 
                    { 
                        string i1 = Convert.ToString(i); 
                        
                        string j1 = j.ToString("00");
                        if (j < 10) 
                        { 
                            //j1 ="0"+j1; 
                            Console.WriteLine(i1 + j1); 
                        } 
                        else 
                        { 
                            Console.WriteLine(i1 + j1); 
                        } 
                    } 
                }
      

  2.   


      
                for (int i = 1; i < 6; i++) 
                { 
                    for (int j = 1; j < 50; j++) 
                    { 
                        string i1 = Convert.ToString(i); 
                        string j1 = j.ToString("00");
                        this.comboBox1.Items.Add(i1+j1);
                    } 
                }
      

  3.   

    for循环又放到那里呢?
    循环的代码会,我的意思是,for语句块放在哪个位置? 
    comboBox控件的那些属性或方法或编辑?
      

  4.   

    类的构造函数里写么(推荐)窗体的Load事件中也行
      

  5.   


            //窗体加载事件
            private void Form1_Load(object sender, EventArgs e)
            {
                for (int i = 1; i < 6; i++) 
                { 
                    for (int j = 1; j < 50; j++) 
                    { 
                        string i1 = Convert.ToString(i); 
                        string j1 = j.ToString("00");
                        this.comboBox1.Items.Add(i1+j1);
                    } 
                }
            }