日期:2014-05-18  浏览次数:20880 次

新人 关于C#中ComboBox的使用方法 在线等
我添加了三个ComboBox控件
分别是年月日
  月份里我添加了12个月份
我想根据月份来判断除2月之外的所有月份的天数 并向日“ComboBox”控件里添加
我把下面的代码写在了月的SelectedValueChanged事件里
但是为什么实现不了啊?
if (cmbMonth.SelectedText == "1" || cmbMonth.SelectedText == "3" || cmbMonth.SelectedText == "5" || cmbMonth.SelectedText == "7" || cmbMonth.SelectedText == "8 " || cmbMonth.SelectedText == "10" || cmbMonth.SelectedText == "12")
  {
  for (int a = 1; a <= 31; a++)
  {
  cmbDay.Items.Add(a);
  }
  }
  else if (cmbMonth.SelectedText == "4" || cmbMonth.SelectedText == "6" || cmbMonth.SelectedText == "8" || cmbMonth.SelectedText == "11")
  {
  for (int b = 1; b <= 30; b++)
  {
  cmbDay.Items.Add(b);
  }
  } 

在线等 高手帮帮我

------解决方案--------------------
C# code

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbDay.Items.Clear();
            if (cmbMonth.Text.Trim() == "1" || cmbMonth.Text.Trim() == "3" || cmbMonth.Text.Trim() == "5" ||
                cmbMonth.Text.Trim() == "7" || cmbMonth.Text.Trim() == "8 " || cmbMonth.Text.Trim() == "10" ||
                cmbMonth.Text.Trim() == "12") 
            { 
                for (int a = 1; a  <= 31; a++) 
                { 
                    cmbDay.Items.Add(a); 
                } 
            }
            else if (cmbMonth.Text.Trim() == "4" || cmbMonth.Text.Trim() == "6" || cmbMonth.Text.Trim() == "8"
                || cmbMonth.Text.Trim() == "11") 
            { 
                for (int b = 1; b  <= 30; b++) 
                { 
                    cmbDay.Items.Add(b); 
                } 
            }  

        }