6.C#WinForm基础城市选择器

源码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 省市选择器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox2.Items.Clear();//清空旧数据
            string 省 = Convert.ToString(comboBox1.SelectedItem);
            if (省 =="河南")
            {
                comboBox2.Items.Add("郑州");
                comboBox2.Items.Add("安阳");
                comboBox2.Items.Add("洛阳");
            }
            if (省 == "山东")
            {
                comboBox2.Items.Add("潍坊");
                comboBox2.Items.Add("济宁");
                comboBox2.Items.Add("青岛");
            }
            if (省 == "辽宁")
            {
                comboBox2.Items.Add("沈阳");
                comboBox2.Items.Add("鞍山");
                comboBox2.Items.Add("本溪");
            }
        }
    }
}

程序截图:

 

posted @ 2014-08-04 14:13  技术宅星云  阅读(2097)  评论(0编辑  收藏  举报