|
DropDownList是web上的控件;ComboBox是winform的控件。
假设窗体叫Form1;
显示国产车和进口车的ComboBox叫comboBox1;
显示具体品牌的ComboBox叫comboBox2。
完成Form1_Load和comboBox1_SelectedIndexChanged这两个事件的代码。
private void Form1_Load(object sender, System.EventArgs e)
{
comboBox1.Items.Add("国产车");
comboBox1.Items.Add("进口车");
comboBox1.SelectedIndex = 0;
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
comboBox2.Items.Clear();
if(comboBox1.Text=="国产车")
{
comboBox2.Items.Add("北京吉普");
comboBox2.Items.Add("上海大众");
comboBox2.Items.Add("北京现代");
comboBox2.SelectedIndex = 0;
}
else if(comboBox1.Text=="进口车")
{
comboBox2.Items.Add("保时捷");
comboBox2.Items.Add("奔驰");
comboBox2.Items.Add("法拉利");
comboBox2.SelectedIndex = 0;
}
}
|