Click here to Skip to main content
15,742,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
tengo estas opciones, quiero mostrar dentro un combobox y asignar un valor a cada uno.

Valor Tipo




despues de hacer una seleccion mostrar con un boton el valor de una opcion seleccionada en un


I have these options, I want to show inside a ComboBox and assign a value to each one.

Type value

_ 1 _____ Dog

_ 2 _ _____ Cat

_ 3 _____ Ave

After making a selection show with a button the value of a selected option in a MessageBox.

What I have tried:

comboBox1.Items.Add(1, "Perro");
Updated 15-Oct-17 19:36pm

1 solution

The simplest way is to create a class:
public class MyClass
   public int Valor { get; set; }
   public string Tipo { get; set; }
And then create a collection of them:
List<MyClass> options = new List<MyClass>();
options.Add(new MyClass() { Valor = 1, Tipo = "Perro" });
options.Add(new MyClass() { Valor = 2, Tipo = "Gato" });
options.Add(new MyClass() { Valor = 3, Tipo = "Ave" });
cbOptions.DataSource = options;
You can then select the display property, and value property:
cbOptions.DisplayMember = "Tipo";
cbOptions.ValueMember = "Valor";
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900