网站建设资讯

NEWS

网站建设资讯

C#中comboBox实现三级联动-创新互联

实现效果:

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册虚拟主机、营销软件、网站建设、邢台县网站维护、网站推广。

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)
 {

 }
 }
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文题目:C#中comboBox实现三级联动-创新互联
当前链接:http://cdweb.net/article/ddgcei.html