我是靠谱客的博主 合适大象,这篇文章主要介绍C#中comboBox实现三级联动,现在分享给大家,希望可以做个参考。

实现效果:

Form1.cs代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Collections; namespace Select { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Hashtable province = new Hashtable(); Hashtable city = new Hashtable(); private void Province() { province.Add("云南省",new string[] {"昆明市","玉溪市" }); province.Add("四川省", new string[] { "成都市", "绵阳市" }); city.Add("昆明市",new string[] {"盘龙区","五华区" }); city.Add("玉溪市",new string[] {"红塔区","。。。区" }); city.Add("成都市", new string[] { "。。。区", "。。。区" }); city.Add("绵阳市", new string[] { "...区", "...区" }); } private void Form1_Load(object sender, EventArgs e) { Province(); foreach (string str in province.Keys) { comboBox1.Items.Add(str); } foreach (string str in city.Keys) { comboBox2.Items.Add(str); } comboBox1.SelectedIndex=0; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string[] citys = province[comboBox1.Text] as string[]; comboBox2.Items.Clear(); foreach (string s in citys) { comboBox2.Items.Add(s); } comboBox2.SelectedIndex = 0; } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { string[] citys = city[comboBox2.Text] as string[]; comboBox3.Items.Clear(); foreach (string str in citys) { comboBox3.Items.Add(str); } comboBox3.SelectedIndex = 0; } private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { } } }

更多相关的实现方法大家可以阅读下面的相关内容,感谢大家对靠谱客的支持。

本文转载于:https://www.idaobin.com/archives/970.html

最后

以上就是合适大象最近收集整理的关于C#中comboBox实现三级联动的全部内容,更多相关C#中comboBox实现三级联动内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(150)

评论列表共有 0 条评论

立即
投稿
返回
顶部