实现效果:
Form1.cs代码
使用系统; 使用System.Collections.Generic; 使用System.ComponentModel; 使用System.Data; 使用System.Drawing; 使用来; 使用text; 使用System.Threading.Tasks; 使用System.Windows.Forms; 使用System.Collections; 名称空间选择 { 公共部分中类Form1:形式 { 公共Form1 () { InitializeComponent (); } Hashtable?new散列表(); Hashtable城市=new散列表(); 私人空间省() { 省。添加(“云南省”,新string[]{“昆明市”,“玉溪市"}); 省。添加(“四川省”,新string[]{”成都市”,“绵阳市"}); 的城市。添加(“昆明市”,新string[]{“盘龙区”,“五华区"}); 的城市。添加(“玉溪市”,新string[]{“红塔区”,“……区”}); 的城市。添加(“成都市”,新string[]{“…区”,“……区”}); 的城市。添加(“绵阳市”,新string [] {”……区”、“…区"}); } 私人空间Form1_Load(对象发送方,EventArgs e) { 省(); foreach (string str province.Keys) { comboBox1.Items.Add (str); } foreach (string str city.Keys) { comboBox2.Items.Add (str); } comboBox1.SelectedIndex=0; } 私人空间comboBox1_SelectedIndexChanged(对象发送方,EventArgs e) { string[]=省[comboBox1城。文本]string []; comboBox2.Items.Clear (); 在北京市foreach(字符串) { comboBox2.Items.Add(年代); } comboBox2。SelectedIndex=0; } 私人空间comboBox2_SelectedIndexChanged(对象发送方,EventArgs e) { string [] [comboBox2全市=城市。文本]string []; comboBox3.Items.Clear (); foreach (string str在城市) { comboBox3.Items.Add (str); } comboBox3。SelectedIndex=0; } 私人空间comboBox3_SelectedIndexChanged(对象发送方,EventArgs e) { } } }
更多相关的实现方法大家可以阅读下面的相关内容,感谢大家对的支持。
本文转载于:https://www.idaobin.com/archives/970.html