选中的列表框项目已选中 [英] checked list box items checked

查看:53
本文介绍了选中的列表框项目已选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框,其中包含item1,item2,item3,item4,item5,item6 .... item10

我有一个由20个功能组成的复选框列表


每个组合框项目具有不同的功能

当我单击组合框项目时,属于该项目的所有功能将

设置为选中

您能帮我怎么做吗

i have one combobox having item1, item2, item3, item4, item5, item6.......item10

i have a checked list box consist of 20 functions


each combobox item has different functions

when i click on combobox items then all the functions belonging to that item will

be set as checked

can u help me how to do this

推荐答案

您需要将功能分组为array list.在组合框selected index change事件上,您需要将array/list与组合框中选择的项目进行匹配.然后运行foreach循环,并将所有项目与array/list中的项目匹配,并将其设置为选中状态.如果您不明白我的意思,请在评论中再次提问.
You will need to group your functions in an array or a list. On combobox selected index change event you need to match the array/list with the item choosen in combobox. Then run a foreach loop and match all the items with the one in array/list and set them to checked. If you didn''t get my point, ask again in comments.


我认为,

1)它是Windows应用程序
2)您有一个带有10个项目的ComboBox.
3)您有20个项目的CheckedListBox和
4)业务是,从ComboBox中选择的每个项目都会检查相关的CheckedListBox项目,例如

Item1 => {Option1,Option2}
Item2 => {Option1,Option2,Option4}等.

以下代码可能会对您有所帮助,

I assume ,

1) It is a Windows application
2) You have a ComboBox with 10items.
3) You have CheckedListBox with 20items and
4) The business is, Every item selection from the ComboBox will check associate CheckedListBox items, for example,

Item1 =>{ Option1, Option2 }
Item2 =>{ Option1, Option2,Option4 } etc.

Following code might help you,

namespace Gui_ComboBox
{
    using System.Linq;
    using System.Windows.Forms;
    public partial class frmMain : Form
    {

        private Dictionary<string, string> StrategyOfSelection = new Dictionary<string, string>()
        {
            {"Item1","Option1,Option2"},
            {"Item2","Option3,Option5,Option3,Option11"},
            {"Item3","Option3,Option5,Option9,Option6"},
            {"Item4","Option4,Option7,Option14,Option8,Option6"},
            {"Item5","Option3,Option5,Option8,Option13,Option15,Option17"}
            // So On...
        };
        public frmMain()
        {
            InitializeComponent();
        }

        private void cbSelector_SelectedIndexChanged(object sender, EventArgs e)
        {
            UnCheckedAll();
            if (StrategyOfSelection.Keys.Contains(cbSelector.SelectedItem.ToString()))
            {
                string[] optionsToSelect = StrategyOfSelection[cbSelector.SelectedItem.ToString()].Split(new char[] { ',' });
                foreach (string item in optionsToSelect)
                {
                    clbOptions.SetItemChecked(clbOptions.FindStringExact(item), true);
                }
            }
        }

        private void UnCheckedAll()
        {
            for (int i = 0; i < this.clbOptions.Items.Count; ++i)
                clbOptions.SetItemChecked(i, false);
        }
    }
}



:)



:)


这篇关于选中的列表框项目已选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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