Removing items from a ComboBox

1

I have a Status that looks for 13 statuses of a table:

cboStatus.DisplayMember = "nome";
cboStatus.ValueMember = "codigo";
cboStatus.DataSource = CartoesVTBLL.Status();
cboStatus.SelectedValue = "";

In this table I have the Constraint field that has the code of these statuses. However, this Constraint is to show, that is, when ComboBox is in the code A and the table has Constraint "O; C; D" I will show only to change the statuses of O, C, and D. Basically I'm going to remove everything that is different from these statuses, I know I'll use the split to separate the codes but how can I get into that rule, maybe a

remove.items.where(x => x.codigo != status.codigo)
    
asked by anonymous 16.08.2017 / 15:38

3 answers

1

Since you are assigning DataSource to ComboBox , you can not manipulate your item collection manually.

For your case, just do as you imagined:

cboStatus.DataSource = CartoesVTBLL.Status().Where(x => x.codigo != status.codigo);
    
16.08.2017 / 19:01
0

You could add these values into a list.

List<String> lista = new List<String>();

And remove unwanted value

var itemToRemove = resultlist.Single(r => r.item == "O"); // ou os valores que deseja
lista.Remove(itemToRemove);

After this you clean your ComboBox

cmbBox.Items.Clear();

And add within the combobox the values that are left in the list.

    
16.08.2017 / 16:02
0

I managed to get the result I wanted, but I think there should be a much simpler way, in any case thanks to the 2 for the answer.

 string[] Array_Restricao = new string[13];               

                List<Cartao_Status> Lista_Status = new List<Cartao_Status>();               
                List<Cartao_Status> Lista_Att = new List<Cartao_Status>();                

                Lista_Status = CartoesVTBLL.Status("", "A");
                string Restricao = Lista_Status.First(x => x.Codigo == cartaoDTO.Status.Codigo).Restricao;

                Array_Restricao = Restricao.Substring(0, Restricao.Length - 1).Split(';');

                foreach (var res in Array_Restricao)
                {
                    Lista_Att.Add(Lista_Status.First(x => x.Codigo == res));
                }
                Lista_Att.Add(Lista_Status.First(x => x.Codigo == cartaoDTO.Status.Codigo));
                cboStatus.DataSource = Lista_Att;
    
16.08.2017 / 20:28