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