1
How to clean the combobox without losing the items?
I try to clean up the combobox in C#, but either it eliminates all options or the selected one, as I do to clean without losing items?
1
How to clean the combobox without losing the items?
I try to clean up the combobox in C#, but either it eliminates all options or the selected one, as I do to clean without losing items?
5
For this you must set the selectedIndex to the first value of your combo box. In this case it would be the index "-1".
Example:
comboBox1.SelectedIndex = -1;
0
You may be saving, for example, 20 items from your comboBox1 in a vector and then you can erase the data contained in the 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]);
}
Browser other questions tagged c# winforms combobox
You are not signed in. Login or sign up in order to post.
What do you mean "clean up"?
– ramaral