How to handle ComboBOX

-1

Hello everyone, I have 2 comboBox and I have 1 (one) file with texts and subtexts

texto1

< 001 > ola

Hi

texto2

home

< 002 > hospital

....

I want to load this information in the 2 combobox

Combobox1 = Text1

Combobox2 = subtexts

ex1:

Combobox1 = Text1

Combobox2 = Wave

ex2:

Combobox1 = Text2

Combobox2 = home

I hope you understand and help me please

    
asked by anonymous 29.12.2016 / 03:21

1 answer

1

You can create a list and assign it to the combobox.

public sealed class ComboBoxItem
{
    public string Texto { get; set; }
    public string Valor { get; set; }

    public override string ToString()
    {
        return this.Texto;
    }
 }

Usage:

   var itens = new List<ComboBoxItem>();
   itens.Add(new ComboBoxItem { Valor = "1", Texto = "Ola" });
   itens.Add(new ComboBoxItem { Valor = "2", Texto = "Oi" });

   cbo.DataSource = itens;
   cbo.DisplayMember = "Texto";
   cbo.ValueMember = "Valor";

Redeem selected value:

var item = (ComboBoxItem)cbo.SelectedItem;   
    
29.12.2016 / 12:12