c#窗体列表框(combobox)应用——省市区列表选择实例

效果如下:

designer.cs代码如下:

using System.Collections.Generic;

namespace 删除
{
    public partial class 省市区选择
    {
        private Dictionary<string, List<string>> provinceCityDictionary;
        private Dictionary<string,List<string>> henanCities = new Dictionary<string,  List<string>>();
        private void InitializeComboBoxes()
        {
           
            // 将所有省份添加到第一个ComboBox
            comboBoxProvinces.DataSource = new List<string>(provinceCityDictionary.Keys);

            // 订阅省份ComboBox的SelectedIndexChanged事件
            comboBoxProvinces.SelectedIndexChanged += comboBoxProvinces_SelectedIndexChanged;
            comboBoxCities.SelectedIndexChanged += comboBoxCities_SelectedIndexChanged;
            comboBoxProvinces.SelectedIndex = -1;
            comboBoxCities.SelectedIndex = -1;
            comboBoxqu.SelectedIndex = -1;
        }

        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要修改
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(省市区选择));
            this.comboBoxProvinces = new System.Windows.Forms.ComboBox();
            this.comboBoxCities = new System.Windows.Forms.ComboBox();
            this.comboBoxqu = new System.Windows.Forms.ComboBox();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // comboBoxProvinces
            // 
            this.comboBoxProvinces.DropDownStyle = System.Windows.Forms.ComboBoxStyle.Simple;
            this.comboBoxProvinces.FormattingEnabled = true;
            this.comboBoxProvinces.Location = new System.Drawing.Point(12, 7);
            this.comboBoxProvinces.Name = "comboBoxProvinces";
            this.comboBoxProvinces.Size = new System.Drawing.Size(205, 366);
            this.comboBoxProvinces.TabIndex = 0;
            this.comboBoxProvinces.SelectedIndexChanged += new System.EventHandler(this.comboBoxProvinces_SelectedIndexChanged);
            // 
            // comboBoxCities
            // 
            this.comboBoxCities.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.comboBoxCities.FormattingEnabled = true;
            this.comboBoxCities.Location = new System.Drawing.Point(223, 7);
            this.comboBoxCities.Name = "comboBoxCities";
            this.comboBoxCities.Size = new System.Drawing.Size(223, 20);
            this.comboBoxCities.TabIndex = 1;
            this.comboBoxCities.SelectedIndexChanged += new System.EventHandler(this.comboBoxCities_SelectedIndexChanged);
            // 
            // comboBoxqu
            // 
            this.comboBoxqu.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.comboBoxqu.FormattingEnabled = true;
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山水CAD插件定制

你的鼓励是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值