关联数据库
1 public Form1() 2 { 3 InitializeComponent(); 4 5 //绑定省 6 comboBox1.DataSource = new ChinaData().Select("0001"); 7 comboBox1.DisplayMember = "AreaName"; 8 comboBox1.ValueMember = "AreaCode"; 9 10 //绑定市11 comboBox2.DataSource = new ChinaData().Select(comboBox1.SelectedValue.ToString());12 comboBox2.DisplayMember = "AreaName";13 comboBox2.ValueMember = "AreaCode";14 15 //绑定区县16 comboBox3.DataSource = new ChinaData().Select(comboBox2.SelectedValue.ToString());17 comboBox3.DisplayMember = "AreaName";18 comboBox3.ValueMember = "AreaCode";19 20 }21 22 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)23 {24 //绑定市25 comboBox2.DataSource = new ChinaData().Select(comboBox1.SelectedValue.ToString());26 comboBox2.DisplayMember = "AreaName";27 comboBox2.ValueMember = "AreaCode";28 }29 30 private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)31 {32 //绑定区县33 comboBox3.DataSource = new ChinaData().Select(comboBox2.SelectedValue.ToString());34 comboBox3.DisplayMember = "AreaName";35 comboBox3.ValueMember = "AreaCode";36 }