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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -