修改ComboBox.Items方法举例

 1 public partial class Form1 : Form
 2  
 3 {
 4 string[] catigories ={ "months", "days" };
 5 string[] months ={ "jan", "feb", "mars", "apri" };
 6 string[] days = { "sat", "sun", "mon" };
 7 public Form1()
 8 {
 9 InitializeComponent();
10 }
11 private void Form1_Load(object sender, EventArgs e)
12 {
13 comboBox1.Items.AddRange(catigories);
14 comboBox1.SelectedIndex = 0;
15 }
16 private void comboBox1_SelectedIndexChanged(objectsender, EventArgs e)
17 {
18 if (comboBox1.SelectedIndex == 0)
19 {
20 comboBox2.Items.Clear();
21 comboBox2.Items.AddRange(months);
22 comboBox2.SelectedIndex = 0;
23 }
24 else if (comboBox1.SelectedIndex == 1)
25 {
26 comboBox2.Items.Clear();
27 comboBox2.Items.AddRange(days);
28 comboBox2.SelectedIndex = 0;
29 }
30 }
31 }

摘自:http://social.msdn.microsoft.com/Forums/vstudio/en-US/e016b307-0e25-4af2-89a5-3ced8b3c2a7b/combobox-items?forum=csharpgeneral

原文地址:https://www.cnblogs.com/fjfhxotfl/p/3419714.html