How to Add, Remove,Find items from combobox in c# visual studio.

COMBOBOX EXAMPLE
First Add three buttons and one combobox from the toolbox and then follow these steps.
Step 1- To add items from combobox go to the button1_click event and copy the following code.

 private void button1_Click(object sender, EventArgs e)

        {
            comboBox1.Items.Add("box");
            comboBox1.Items.Add("pen");
            comboBox1.Items.Add("bat");
            comboBox1.Items.Add("mat");
            comboBox1.Items.Add("van");

        }


Step 2- To remove Selected item from combobox go to the button2_click event and copy the following code.


private void button2_Click(object sender, EventArgs e)

        {
            comboBox1.Items.Remove(comboBox1.SelectedItem);
        }

Step 3-To find the item from combobox we need to add one Textbox from toolbox to input text and then go to the button3_click event and copy the following code.


  private void button3_Click(object sender, EventArgs e)

        {
            int index = comboBox1.FindString(textBox1.Text);
            comboBox1.SelectedIndex = index;
        }

Comments

Popular Posts