当前位置: 移动技术网 > IT编程>开发语言>c# > C#中comboBox实现三级联动

C#中comboBox实现三级联动

2019年07月18日  | 移动技术网IT编程  | 我要评论
实现效果: form1.cs代码 using system; using system.collections.generic; using syste

实现效果:

form1.cs代码

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

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网