三级联动[省,市,区]
类似地区选择,当选的某个省份,后面的下拉框相对变成对应省份的区县
实现省市区联动关键是数据库的表,[每个省内区的AreaCode列是同样的]
public Form2() { InitializeComponent(); //绑定省 comboBox1.DataSource = new ChinaData().Select("0001"); comboBox1.DisplayMember = "AreaName"; comboBox1.ValueMember = "AreaCode"; //绑定市 comboBox2.DataSource = new ChinaData().Select(comboBox1.SelectedValue.ToString()); comboBox2.DisplayMember = "AreaName"; comboBox2.ValueMember = "AreaCode"; //绑定区县 comboBox3.DataSource = new ChinaData().Select(comboBox2.SelectedValue.ToString()); comboBox3.DisplayMember = "AreaName"; comboBox3.ValueMember = "AreaCode"; } // 当省列表选项改变时 绑定相应的市 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { comboBox2.DataSource = new ChinaData().Select(comboBox1.SelectedValue.ToString()); comboBox2.DisplayMember = "AreaName"; comboBox2.ValueMember = "AreaCode"; } // 当市列表选项改变时 绑定相应的区县 private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { comboBox3.DataSource = new ChinaData().Select(comboBox2.SelectedValue.ToString()); comboBox3.DisplayMember = "AreaName"; comboBox3.ValueMember = "AreaCode"; }