Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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.
 
Share this answer
 
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,

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


:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900