Combobox Text is different from the drop-down list.

I want to have a combobox with a drop-down list of codes and definitions, but display only the definition of the selected item in the text box part. For example, Y-Yes and N-No in the drop-down list, and when Y is selected, only "Yes" is displayed in the text box.

+3
source share
1 answer

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.

0
source

Source: https://habr.com/ru/post/1770616/


All Articles