combobox - Windows Forms C# Combo Box List Box -
combobox - Windows Forms C# Combo Box List Box -
private void cmbusers_selectedindexchanged(object sender, eventargs e) { if (cmbusers.selectedtext == "<all users>") { //do stuff } else if (cmbusers.selectedtext == "dbo") { //do stuff } else if (cmbusers.selectedtext == "information_schema") { //do stuff } else if (cmbusers.selectedtext == "sys") { //do stuff } }
i have form on there combo box , list box.
when user select combo box list list box records should shown . when user select dbo dbo.abc records should shown in list box. when user select information_schema records information_schema.abc should shown. english language not great . hope understand question.
please help me.
there plenty ways resolve this.
my first effort should create dictionary<string, list<string>>
, add together keys combobox. keys "dbo.abc" , on , values corresponding records. on combobox index changed event, clear listbox , add together items corresponding list it.
for items, can add together "all list" item in combobox. then, on test see if key exists in dictionary, if doesn't exists, can foreach
on yourdictionary.values
, add together them listbox.
that's way i'll it. there plenty others , maybe should start improve c# language before asking trivial questions :)
edit on illustration (supposing listbox cmblist) :
private dictionary<string, list<string>> _items; private void cmbusers_selectedindexchanged(object sender, eventargs e) { var cmbtext = cmbusers.selectedtext; cmblist.items.clear(); if (_items.containskey(cmbtext) { cmblist.items.addrange(_items[cmblist]); } else // default : show items { foreach (var val in _items.values) { cmblist.items.addrange(val); } } }
c# combobox listbox
Comments
Post a Comment