title: How can I select an item in a wpf combobox when it is a prefix of a previous item?
body: <p>I'll start with my code example.  It's a WPF Application.</p>
  
  <p>MainWindow.xaml:</p>
  
  <pre><code>&lt;Window x:Class="DemoComboBoxProblem.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:DemoComboBoxProblem"
          mc:Ignorable="d"
          Title="MainWindow" Height="60" Width="200"&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="Auto" /&gt;
              &lt;ColumnDefinition Width="Auto" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;ComboBox Name="CB0" Grid.Column="0" Width="60"&gt;
              &lt;ComboBoxItem&gt;CRLF&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem&gt;CR&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem&gt;LF&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem&gt;LFCR&lt;/ComboBoxItem&gt;
          &lt;/ComboBox&gt;
          &lt;ComboBox Name="CB1" Grid.Column="1" Width="60"&gt;
              &lt;ComboBoxItem&gt;CRLF&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem&gt;AA&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem&gt;BB&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem&gt;LFCR&lt;/ComboBoxItem&gt;
          &lt;/ComboBox&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>MainWindow.xaml.cs:</p>
  
  <pre><code>using System.Windows;
  
  namespace DemoComboBoxProblem
  {
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
  
              CB0.Text = "CR";
              CB1.Text = "AA";
          }
      }
  }
  </code></pre>
  
  <p>I want to programatically select the item "CR" in CB0 and the item "AA" in CB1.</p>
  
  <p>When I run this, CB0 displays nothing and (I assume) no item is selected in it.  CB1 correctly displays and has selected "AA".  I think this has something to do with "CR" being a prefix of "CRLF".  I can get it to work if I change the order of the items, but I'm wondering: what is the correct way to make it work with the items in the order given?</p>
  
  <p>Thanks</p>