if(CurProvince.SelectedText=="河北")
{
CurCity.Items.Add("石家庄");
CurCity.Items.Add("唐山");
}
CurProvince和CurCity是两个comboBox控件
为什么我在CurProvince中选择一个“河北”时,不能把“石家庄”和“唐山”添加进CurCity的下拉列表框呢?
程序哪里有问题啊?
{
CurCity.Items.Add("石家庄");
CurCity.Items.Add("唐山");
}
CurProvince和CurCity是两个comboBox控件
为什么我在CurProvince中选择一个“河北”时,不能把“石家庄”和“唐山”添加进CurCity的下拉列表框呢?
程序哪里有问题啊?
下面这段是我自己写的,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");
}
}
Windows 有点 问题你通过事件了 实现SelectedObject
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("河北省");
}