组合框中的索引逻辑? [英] Index logic in combobox ?

查看:92
本文介绍了组合框中的索引逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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;
   }

推荐答案

第一个组合框和第二个组合框中的项目之间的连接也在其他地方(至少应该是)建模.在数据库中的表或链接类中.
这意味着,在第一个组合框的SelectedIndexChanged事件中(请注意:检查它是否不是-1!),您将从数据库表中获取元素以筛选combobox1的值,或者使用例如来过滤链接类中的数据. Linq,然后填充第二个组合框.
您已经采用了正确的方法,只需使用数据之间的链接即可.
The connection between the items in the first combobox and the second combobox is modelled also somewhere else (at least ought to be), e.g. in a table in a database or in a linking class.
That means, in the SelectedIndexChanged event of the first combobox (note: check that it is not -1!), you get the elements from the database table filtering for the value of combobox1, or you filter the data in the linking class with e.g. Linq, and then fill the second combobox.
You are already on the right way, just use that link between the data.


这篇关于组合框中的索引逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆