winforms - C# Windows Forms how to change values of second combo box based on selection in first combo box -


i attempting create order form , such using combo boxes in order let user choose item going ordered. such when user selects item going ordered, second combo box should change sizes specific item can ordered in. have filled second combo box sizes items unsure how limit sizes per item selected. have tried using if statements addrange second combo box duplicates items @ end of combo box. can given on appreciated. thanks

   private void itembox_selectedindexchanged(object sender, eventargs e)    {         switch (((combobox)sender).selecteditem string)         {             case "name in frame":                 sizebox.selectedindex = 0;                 break;             case "scrabble frame":                 sizebox.selectedindex = 1;                 break;             case "plaque":                 sizebox.selectedindex = 2;                 break;             case "hearts":                 sizebox.selectedindex = 3;                 break;             case "now , forever print":                 sizebox.selectedindex = 4;                 break;             case "pat cushion":                 sizebox.selectedindex = 5;                 break;             case "emilia cushion":                 sizebox.selectedindex = 6;                 break;         }     }      private void sizebox_selectedindexchanged(object sender, eventargs e)     {         if (sizebox.selectedindex == 0)         {             this.sizebox.items.addrange(new object[]{                 "7x5",                 "10x8",                 "a4",                 "mug"             });         }     } 

you populate sizebox collection directly itembox selected change event handler , remove sizebox_selectedindexchanged altogether.

however, achieve what, need clear items in sizebox once item has been selected. can achieve via:

sizebox.items.clear(); 

you can add items once sizebox selected index has changed. use:

sizebox.items.add("new size"); 

for practice remove use of magic strings, maybe put them in products helper class returns appropriate string.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -