Search
 
SCRIPT & CODE EXAMPLE
 

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());
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# check if array contains value 
Csharp :: C# Read() and ReadKey() 
Csharp :: c# make file not read only 
Csharp :: get int value from enum c# 
Csharp :: element click intercepted exception in selenium C# 
Csharp :: How to add rigidbody as a variable 
Csharp :: LINQ: 2 join with group by 
Csharp :: deploy .net core 
Csharp :: c# datagridview double click on cell 
Csharp :: serial number unity pro 
Csharp :: c# dictionary with dictionary as value 
Csharp :: c# list find index 
Csharp :: System.Data.Entity.Core.EntityException: The underlying provider failed on Open 
Csharp :: longest substring without repeating characters c# 
Csharp :: how to convert timestamp to datetime c# 
Csharp :: c sharp 
Csharp :: calculator in c# 
Csharp :: get mouse inpuit new input system 
Csharp :: c# write line 
Csharp :: c# callback param 
Csharp :: unity get audio clip length 
Csharp :: aspx receive variable from url 
Csharp :: c# centos Regex Username 
Csharp :: monogame print debug 
Csharp :: instantiate type c# 
Csharp :: unity apply bloom of a different color 
Csharp :: linear search algorithm c# 
Csharp :: c# Sum of all the factors of a number 
Csharp :: c# clear linkList 
Csharp :: vb.net delete folder if exists 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =