César Amorim
César Amorim

Reputation: 357

How to hide items in combo-boxes?

I have a combobox with various items, item1 item2 item3

They all show as visible and are selectable, but i wanna hide for example item3, i want him to appear only when a variable equals 1

is this possible? Because all of the items i have in the collection including item3 are showing up.

I'm using the following to disable its selection

  if (ComboBox1.SelectedItem == "item3")
        {
            ComboBox1.SelectedIndex = -1;
  }

and it works fine, but i wanna actualy make item3 invisible unless other variable is set as 1

Upvotes: 0

Views: 1331

Answers (1)

Adam H
Adam H

Reputation: 126

I would wait until the other variable is set and then add that item to the combo box. Something like this.

if (variable == 1) {
    ComboxBox1.Items.Add("item3");
}

Upvotes: 1

Related Questions