title: Prevent WPF combobox clearing selection when itemssource changes
body: <p>I have a textbox for firstname, a textbox for lastname, and a combobox for displayname.  The displayname is editable so that the user can type in whatever they want.  However, the combobox should display a list of options.</p>
  
  <p>When either textbox changes, the combobox itemssource is updated.  However, if the user previously <strong>selected</strong> a value, then the text property is blanked out.  But if the user had <strong>typed</strong> in a value, the text property remains.  How do i prevent the text value from blanking out?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;Window x:Class="MainWindow"
          x:Name="MainApp"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow"
          Height="350"
          Width="525"&gt;
      &lt;Grid DataContext="{Binding ElementName=MainApp}"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="*" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;TextBox Grid.Row="0"
                   Text="{Binding FirstName}" /&gt;
          &lt;TextBox Grid.Row="1"
                   Text="{Binding LastName}" /&gt;
          &lt;ComboBox x:Name="MyCb" Grid.Column="1"
                    Grid.Row="2" 
                    Text="{Binding TheName}"
                    ItemsSource="{Binding NameOptions}"
                    IsEditable="True" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  
  Imports System.ComponentModel
  
  Class MainWindow
      Implements INotifyPropertyChanged
  
      Public ReadOnly Property NameOptions As List(Of String)
          Get
              Dim result As New List(Of String)
              result.Add(String.Format("{0} {1}", FirstName, LastName))
              result.Add(String.Format("{1}, {0}", FirstName, LastName))
              result.Add(String.Format("{1}, {0} MI", FirstName, LastName))
              Return result
          End Get
      End Property
  
      Public Property TheName As String
  
      Private _firstName As String
      Public Property FirstName As String
          Get
              Return _firstName
          End Get
          Set(value As String)
              _firstName = value
              RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("FirstName"))
              RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("NameOptions"))
          End Set
      End Property
  
      Private _lastname As String
      Public Property LastName As String
          Get
              Return _lastname
          End Get
          Set(value As String)
              _lastname = value
              RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("LastName"))
              RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("NameOptions"))
          End Set
      End Property
  
      Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
  End Class
  </code></pre>