源码如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 省市选择器 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { comboBox2.Items.Clear();//清空旧数据 string 省 = Convert.ToString(comboBox1.SelectedItem); if (省 =="河南") { comboBox2.Items.Add("郑州"); comboBox2.Items.Add("安阳"); comboBox2.Items.Add("洛阳"); } if (省 == "山东") { comboBox2.Items.Add("潍坊"); comboBox2.Items.Add("济宁"); comboBox2.Items.Add("青岛"); } if (省 == "辽宁") { comboBox2.Items.Add("沈阳"); comboBox2.Items.Add("鞍山"); comboBox2.Items.Add("本溪"); } } } }
程序截图: