Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# combobox with text and value

//link : https://stackoverflow.com/questions/3063320/combobox-adding-text-and-value-to-an-item-no-binding-source

public class ComboboxItem
{
    public string Text { get; set; }
    public object Value { get; set; }

    public override string ToString()
    {
        return Text;
    }
}

// usage

private void Test()
{
    ComboboxItem item = new ComboboxItem();
    item.Text = "Item text1";
    item.Value = 12;

    comboBox1.Items.Add(item);

    comboBox1.SelectedIndex = 0;

    MessageBox.Show((comboBox1.SelectedItem as ComboboxItem).Value.ToString());
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #combobox #text
ADD COMMENT
Topic
Name
2+3 =