组合框的元素过滤 [英] Combobox's elements filtering
本文介绍了组合框的元素过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有combobox1和comboox2,在combobox1中,我的元素是A,B,C和combobox2 1,2,3,4,5,6 ...
当我选择"A"时,相关的1、2、3和B相关的3,4和C相关的5,6.我只想看1,2,3;选取[时; B"只需3,4等.
我怎么能想象呢?
我尝试在选定的索引中进行更改,但是我没有
I have combobox1 and comboox2 and in combobox1 my elements are A,B,C and combobox2 1,2,3,4,5,6...
A related 1,2,3 and B related 3,4 and C related 5,6.When I choose "A" I want to see just 1,2,3 ; when select "B" just 3,4 etc.
How can I imagine it ?
I tried to do in selected index changed but I didn''t
推荐答案
您好,
试试这个:
Hello,
Try This:
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.AddRange(new string[] { "A", "B", "C" });
comboBox1.SelectedIndex = -1;
comboBox2.Items.Clear();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Items.Clear();
switch (comboBox1.SelectedItem.ToString())
{
case "A":
comboBox2.Items.AddRange(new string[] { "1", "2", "3" });
break;
case "B":
comboBox2.Items.AddRange(new string[] { "3", "4"});
break;
case "C":
comboBox2.Items.AddRange(new string[] { "5", "6" });
break;
default:
break;
}
comboBox2.SelectedIndex = -1;
}
参加
埃内斯托·法佐洛(Ernesto Fazolo)
Att.
Ernesto Fazolo
这篇关于组合框的元素过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文