欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#中comboBox实现三级联动

程序员文章站 2023-12-18 23:00:34
实现效果: form1.cs代码 using system; using system.collections.generic; using syste...

实现效果:

C#中comboBox实现三级联动

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

上一篇:

下一篇: