关于组合框控件问题?
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 组合框控件_comboBox_
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cboCountry.SelectedIndex = 0;
}
private void cboCity_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cboCountry.SelectedIndex)
{
case 0:
cboCity.Items.Clear();
cboCity.Items.Add("北京");
cboCity.Items.Add("上海");
cboCity.Items.Add("成都");
cboCity.Items.Add("天津");
cboCity.SelectedIndex = 0;
break;
case 1:
cboCity.Items.Clear();
cboCity.Items.Add("纽约");
cboCity.Items.Add("华盛顿");
cboCity.Items.Add("芝加哥");
cboCity.SelectedIndex = 0;
break;
case 2:
cboCity.Items.Clear();
cboCity.Items.Add("伦敦");
cboCity.Items.Add("考文垂");
cboCity.Items.Add("曼彻斯特");
cboCity.SelectedIndex = 0;
break;
default :
cboCity.Items.Clear();
break;
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
string aa = cboCountry.SelectedIndex.ToString() + ":" + cboCity.SelectedIndex.ToString();
MessageBox.Show(aa, "国家城市列表", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
请求高手指教
我是新手,我照着书上编的,不知为啥运行程序是只显示国家列表里的“中国”、“美国”、“英国”,而相对应的城市列表就显示不出来了,求指点!!!谢谢
------解决方案--------------------private void cboCity_SelectedIndexChanged(object sender, EventArgs e)
是不是要改为
private void cboCountry_SelectedIndexChanged(object sender, EventArgs e)
你是选择国家后城市列表自己变化吧。
------解决方案--------------------shi d
------解决方案--------------------private void cboCity_SelectedIndexChanged(object sender, EventArgs e)
改为
private void cboCountry_SelectedIndexChanged(object sender, EventArgs e)
应该就可以了额!