title: How to select programatically an item in the combo box when using key,value pair
body: <p>Could someone please explain how I could select programatically an item in the ComboBox when the item is defined like this:</p>
  
  <pre><code>    class ComboboxItem
      {
          public string DisplayString;
          public string Key;
  
          public ComboboxItem(string key, string displayString)
          {
              Key = key;
              DisplayString = displayString;
          }
  
          // Generates the text shown in the combo box
          public override string ToString()
          {
              return DisplayString;
          }
      }
  </code></pre>
  
  <p>The combo box gets populated with items at runtime like this:</p>
  
  <pre><code>myCombo.Items.Add(new ComboboxItem(“&lt;key&gt;“, “&lt;text_to_display&gt;”));
  </code></pre>
  
  <p>I need to select an item programatically based on the key but I cannot use the suggestion made here: <a href="https://stackoverflow.com/questions/8357480/set-the-selecteditem-of-a-combobox-based-on-key-value-pair">Set the selecteditem of a combobox based on key,value pair.</a> because I don't have foreknowledge of the data items as the ComboBox gets populated at runtime. Could someone please help? Many thanks.</p>
  
  <p>EDIT - this is a winforms app.</p>