We can add items to a ComboBox at design-time from Properties Window by clicking on Items Collection and using code.
Add Items at Design Time
Method 1:
Method 2:
When you click on the Collections, the String Collection Editor window will pop up where you can type strings. Each line added to this collection will become a ComboBox item.
Output:
Add Items at Run-Time
We can add same items at run-time by using the following code snippet.
1 2 3 4 5 6 7 8 9 10 |
private void Form1_Load(object sender, EventArgs e) { comboBox1.Items.Add("C#"); comboBox1.Items.Add("C++"); comboBox1.Items.Add("Python"); comboBox1.Items.Add("Java"); comboBox1.Items.Add("SQL"); } |
Output: