If you are using WPF for this, use Binding.
Suppose you are linking a collection of a class:
public class Item
{
public string Key{
get
{
return this.Value[0].ToString();
}
}
public string Value{get;set;}
public override string ToString()
{
return this.Key;
}
}
You can use it to display the key and value, as shown in the figure.
<ComboBox x:Name="cmbList" ItemsSource="{Binding}" Text="{Binding SelectedItem.Value}"></ComboBox>
Hope this helps you solve your problem.
source
share