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

问题描述

我有一个组合框,其中包含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

推荐答案


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);
        }
    }
}



:)



:)


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

09-05 23:25
查看更多