c# - ComboBox Array Selection Display -


hi created array of student , grades question how make if select student sam index 0 , display first array of grades inside combobox. code write tie them together. if me thankful.

    private void form1_load(object sender, eventargs e)     {         string[] student = { "sam", "dean", "nick", "shara", "kat" };         cbostudent.items.addrange(student);         cbostudent.selectedindex = 0;         string[] s1grade = { "math: 78", "english: 56", "bio: 94", "art: 67", "science: 64", "pe: 85", "social: 89" };         cbogrades.items.addrange(s1grade);         string[] s2grade = { "math: 45", "english: 84", "bio: 56", "art: 67", "science: 78", "pe: 45", "social: 76" };         cbogrades.items.addrange(s2grade);         string[] s3grade = { "math: 68", "english: 34", "bio: 98", "art: 56", "science: 55", "pe: 65", "social: 56" };         cbogrades.items.addrange(s3grade);         string[] s4grade = { "math: 38", "english: 78", "bio: 76", "art: 67", "science: 34", "pe: 45", "social: 56" };         cbogrades.items.addrange(s4grade);         string[] s5grade = { "math: 88", "english: 84", "bio: 56", "art: 45", "science: 56", "pe: 85", "social: 89" };         cbogrades.items.addrange(s5grade);     }      private void button1_click(object sender, eventargs e)     {         string selectedstudent = cbostudent.text;         txtselected.text = selectedstudent;     }     private void cbogrades_selectedindexchanged(object sender, eventargs e)     {         string selectedgrade = cbogrades.text;     } 

i use kind of approach:

 public form1()     {         initializecomponent();         string[] student = { "sam", "dean", "nick", "shara", "kat" };         cbostudent.items.addrange(student);         cbostudent.selectedindex = 0;                }      private void combobox1_selectedindexchanged(object sender, eventargs e)     {         cbogrades.items.clear();         cbogrades.items.addrange(selecting(cbostudent.selectedindex));     }       private string[] selecting(int index)     {         string[] arr = null;         switch (index)         {             case 0: arr = new[] { "math: 78", "english: 56", "bio: 94", "art: 67", "science: 64", "pe: 85", "social: 89" }; break;             case 1: arr = new[] { "math: 45", "english: 84", "bio: 56", "art: 67", "science: 78", "pe: 45", "social: 76" }; break;             case 2: arr = new[] { "math: 68", "english: 34", "bio: 98", "art: 56", "science: 55", "pe: 65", "social: 56" }; break;             case 3: arr = new[] { "math: 38", "english: 78", "bio: 76", "art: 67", "science: 34", "pe: 45", "social: 56" }; break;             case 4: arr = new[] { "math: 88", "english: 84", "bio: 56", "art: 45", "science: 56", "pe: 85", "social: 89" }; break;             default: arr = null; break;//no correct index;         }         return arr;     } 

is good? , set comboboxes property of dropdownstyle dropdownlist, user cannot edit it, (on loading time):

   cbostudent.dropdownstyle = comboboxstyle.dropdownlist; 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -