miledizna
miledizna

Reputation: 15

How do I clear all ComboBoxes at once By looping through them?

I have about nine ComboBoxes on my form and each one is filtered according to the one that came before it, so when I change the value of the first ComboBox I need to clear the rest, is there any way to loop through all of them and clear each one? I tried this:

private void Clear()
        {
            foreach (ComboBox cmb in Controls.OfType<ComboBox>())
                cmb.Items.Clear();
        }

Upvotes: 1

Views: 231

Answers (1)

evilGenius
evilGenius

Reputation: 1101

cmb.Items.Clear(); //this  removes the items 
cmb.ResetText(); //this clear text

Upvotes: 1

Related Questions