How to clean the combobox without losing the items?

1

How to clean the combobox without losing the items?

I try to clean the combobox in C #, but either it deletes all the options or the selected one, how do I clean without losing the items?

    
asked by anonymous 27.03.2014 / 20:40

2 answers

4

For this you should set the selectedIndex to the first value of your combo box. In case it would be the index "-1".

Example:

  comboBox1.SelectedIndex = -1;
    
27.03.2014 / 20:53
0

You may be saving 20 items from your comboBox1 in a vector and then you can delete the data contained in comboBox1 .

Declare as global variable

string[] items = new string[20];

To save the data and delete it from comboBox1

int i = 0;
for (i = 0; i <= 19; i++)
{
    comboBox1.SelectedIndex = i;
    items[i] = comboBox1.SelectedItem.ToString();
}
comboBox1.Items.Clear();

To return the data to comboBox1

int i = 0;
comboBox1.Items.Clear();
for (i = 0; i <= 19; i++)
{
    comboBox1.Items.Add(items[i]);
}
    
28.03.2014 / 00:27