问题描述
我有combobox1和comboox2,在combobox1中,我的元素是A,B,C和combobox2 a,b,c,d,e,f ...并且我使用screeen属性添加了此元素(我的意思是不带代码) .
I have combobox1 and comboox2 and in combobox1 my elements are A,B,C and combobox2 a,b,c,d,e,f...And I added this elements using property screeen(I mean not with code).
combobox1 combobox2
----------------- ----------------
A a
B b
C c
d
e
f
A related a,b,c and B related b,c and C related d,e,f.
当我选择"A"时,我只想看到a,b,c;当选择 B" 只B,C等
我可以给combobox1的项目提供索引号吗?当我选择"A"时,我只想看到"a","b","c"元素(我的意思是0,1,2负债数),而当我选择"B"时,我只想看到b,c(我的意思是1,2负债)数字).我想这样做是因为如果没有负债数,我必须与编写代码保持一切联系.我在下面写了一些代码,但是很长的路要走.
When I choose "A" I want to see just a,b,c ; when select "B" just b,c etc.
can I give index number of combobox1''s items ? When I choose "A" I want to see just "a","b","c" elements(I mean 0,1,2 indeks numbers) when choose "B" just b,c (I mean 1,2 indeks numbers). I want to do like that cause if there is no indeks numbers I have to make all relationship with writing codes.I wrote a little code below but it is long way.
Index logic is better, sure if there is index logic in combobox :)
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Items.Clear();
switch (comboBox1.SelectedItem.ToString())
{
case "A":
comboBox2.Items.AddRange(new string[] { "a", "b", "c" });
break;
case "B":
comboBox2.Items.AddRange(new string[] { "b", "c" });
break;
}
comboBox2.SelectedIndex = -1;
}
推荐答案
这篇关于组合框中的索引逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!