Adding Items to ListBox and ComboBox Controls

by Shabbir on May 10, 2008

in C#

Adding items to this controls in .Net is very easy. To demonstrate that we will create a simple project with the following controls:

  • ListBox (name: listBox1)
  • ComboBox (name: comboBox1)
  • TextBox (name: textBox1)
  • Button (text: Add)

So, drag this controls from the toolbox and drop them on the main form one by one. Make a form like this

List box and combo box

Now double click on the button, it will create a button click event. Insert this code there

  1. listBox1.Items.Add(textBox1.Text);
  2. comboBox1.Items.Add(textBox1.Text);
  3. textBox1.Clear();

Now, write something in the text box and then click the button. The text you entered in the textBox1 will be inserted as item in the listBox1 and comboBox1, and the textBox1 text will be cleared.

List box and combo box with data

Sharing is Caring...

Leave a Comment

Previous post:

Next post:

    About the Author

  • author photo

    My Name is Shabbir Bhimani and I am developer by profession in the field of applications, web and database. Currently doing full time online marketing and like to share my experiences on how you can make money online @ CodeItWell.com. Read more ...


    See how you can get in touch with me.