C#中如何使用Combox? 达到的效果:有两个combox,1和2,1作为主关键字,作为次关键字
譬如说combox1选择"数学"时,combox2中添加“123,456”,选择"语文"时,combox2中添加“冯骥才,舒淇”什么的。哪位大侠指点下!!谢谢!我是这么写...
譬如说combox1选择"数学"时,combox2中添加“123,456”,选择"语文"时,combox2中添加“冯骥才,舒淇”什么的。
哪位大侠指点下!!谢谢!
我是这么写的:
private void Form1_Load(object sender, EventArgs e)
{
this.comboBox1.Items.Add("数学");
this.comboBox1.Items.Add("语文");
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.comboBox1.SelectedIndex)
{
case 0:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("123");
this.comboBox2.Items.Add("456");
break;
case 1:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("莎士比亚");
this.comboBox2.Items.Add("冯骥才");
break;
default:
MessageBox.Show("出错了!");
break;
}
测试的时候combox2总是获取不到值。
怎么修改呢? 展开
哪位大侠指点下!!谢谢!
我是这么写的:
private void Form1_Load(object sender, EventArgs e)
{
this.comboBox1.Items.Add("数学");
this.comboBox1.Items.Add("语文");
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.comboBox1.SelectedIndex)
{
case 0:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("123");
this.comboBox2.Items.Add("456");
break;
case 1:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("莎士比亚");
this.comboBox2.Items.Add("冯骥才");
break;
default:
MessageBox.Show("出错了!");
break;
}
测试的时候combox2总是获取不到值。
怎么修改呢? 展开
3个回答
展开全部
我测试了的,直接复制过去就ok,有问题找我。
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Clear();
comboBox1.Items.Add("---请选择---");
comboBox1.Items.Add("数学");
comboBox1.Items.Add("语文");
comboBox1.SelectedIndex = 0;//设置第一行的值默认选中
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.comboBox1.SelectedIndex)
{
case 0:
this.comboBox2.Items.Clear();
comboBox2.Text= "";
break;
case 1:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("123");
this.comboBox2.Items.Add("456");
comboBox2.SelectedIndex = 0;//设置第一行的值默认选中
break;
case 2:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("莎士比亚");
this.comboBox2.Items.Add("冯骥才");
comboBox2.SelectedIndex = 0;//设置第一行的值默认选中
break;
default:
MessageBox.Show("出错了!");
break;
}
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Clear();
comboBox1.Items.Add("---请选择---");
comboBox1.Items.Add("数学");
comboBox1.Items.Add("语文");
comboBox1.SelectedIndex = 0;//设置第一行的值默认选中
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.comboBox1.SelectedIndex)
{
case 0:
this.comboBox2.Items.Clear();
comboBox2.Text= "";
break;
case 1:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("123");
this.comboBox2.Items.Add("456");
comboBox2.SelectedIndex = 0;//设置第一行的值默认选中
break;
case 2:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("莎士比亚");
this.comboBox2.Items.Add("冯骥才");
comboBox2.SelectedIndex = 0;//设置第一行的值默认选中
break;
default:
MessageBox.Show("出错了!");
break;
}
}
2011-06-11
展开全部
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.comboBox1.Text)
{
case "数学":
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("123");
this.comboBox2.Items.Add("456");
break;
case “语文”:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("莎士比亚");
this.comboBox2.Items.Add("冯骥才");
break;
default:
MessageBox.Show("出错了!");
break;
}
这样呢,你试试
{
switch (this.comboBox1.Text)
{
case "数学":
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("123");
this.comboBox2.Items.Add("456");
break;
case “语文”:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("莎士比亚");
this.comboBox2.Items.Add("冯骥才");
break;
default:
MessageBox.Show("出错了!");
break;
}
这样呢,你试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.comboBox1.Text)
{
case "数学":
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("123");
this.comboBox2.Items.Add("456");
break;
case “语文”:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("莎士比亚");
this.comboBox2.Items.Add("冯骥才");
break;
default:
MessageBox.Show("出错了!");
break;
{
switch (this.comboBox1.Text)
{
case "数学":
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("123");
this.comboBox2.Items.Add("456");
break;
case “语文”:
this.comboBox2.Items.Clear();
this.comboBox2.Items.Add("莎士比亚");
this.comboBox2.Items.Add("冯骥才");
break;
default:
MessageBox.Show("出错了!");
break;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询