if(CurProvince.SelectedText=="河北")
{
   CurCity.Items.Add("石家庄");
   CurCity.Items.Add("唐山");
}
CurProvince和CurCity是两个comboBox控件
为什么我在CurProvince中选择一个“河北”时,不能把“石家庄”和“唐山”添加进CurCity的下拉列表框呢?
程序哪里有问题啊?

解决方案 »

  1.   

    看看第一个comboBox的Autopostback属性有没有设置为"True"。如果没有就不能触发服务器事件。
      

  2.   

    是不是你没有加触发事件呢?
    下面这段是我自己写的,comboBox1是省名,comboBox2是城市名。希望对你有帮助。
    private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    if (comboBox1.SelectedItem == "Liao Ning")
    {
    // 换省的时候要先把原来的城市先清除,不然会使新加的城市在原来的下面。程序会出问题的。
                                         comboBox2.Items.Clear();
    comboBox2.Items.Add("Shen Yang");
    comboBox2.Items.Add("Fu Shun");
    }
    if (comboBox1.SelectedItem == "Shang Hai")
    {
    comboBox2.Items.Clear();
    comboBox2.Items.Add("Huang Pu");
    comboBox2.Items.Add("Hong Kou");
    }
    }
      

  3.   

    web 吗!
    Windows 有点 问题你通过事件了 实现SelectedObject
      

  4.   

    comboBox的Autopostback属性我没找到啊?anderose的程序我运行了,好象还是不行啊(除了你写的是拼音,我写的是中文),你有试过,可以吗?
      

  5.   

    其实中文跟英文都一样啦,你自己看看
    private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    switch (this.comboBox1.SelectedItem.ToString().Trim())
    {
    case "广东省":
    this.comboBox2.Text = "";
    this.comboBox2.Items.Clear();
    this.comboBox2.Items.Add("广州市");
    this.comboBox2.Items.Add("佛山市");
    this.comboBox2.SelectedIndex = 0;
    break;
    case "湖南省":
    this.comboBox2.Text = "";
    this.comboBox2.Items.Clear();
    this.comboBox2.Items.Add("长沙市");
    this.comboBox2.SelectedIndex = 0;
    break;
    default:
    break;
    }
    } private void Form1_Load(object sender, System.EventArgs e)
    {
    this.comboBox1.Items.Clear();
    this.comboBox1.Items.Add("广东省");
    this.comboBox1.Items.Add("湖南省");
    this.comboBox1.Items.Add("河北省");
    }
      

  6.   

    检查是不是InitializeComponent方法中,控件的SelectedIndexChanged事件是否已注册回掉方法