title: Listing matching items in a combo box while entering a text?
body: <p>I have a <code>ComboBox</code> in a form and while the user typing some text in the box, if there are matching items in the database with the text typed, should be listed in the <code>ComboBox</code>. So that the user can be notified if the item being entered is already in the database. I'm trying to achieve this as follows. </p>
  
  <p>When a text is entered in the <code>combo</code> it will fire an event. Listening to that event, <code>Presenter</code> will get matching user list from the database and then the list will be set as the <code>DataSource</code> of the <code>ComboBox</code> as follows...</p>
  
  <p>But why it is not displayed in the combo? Please let me know the issue in this code!</p>
  
  <p>Form</p>
  
  <pre><code>public partial class frmUser : Form
  {
      // two seperate get and set properties are used to same combo box as a list will be set as the datasource.
  
      public string UserName 
      {
          get{return cmbUserName.Text;}
      }
  
      public IEnumerable&lt;User&gt; UserList
      {
          set { cmbUserName.DataSource = value; }
      }
      private void cmbUserName_TextChanged(object sender, EventArgs e)
      {
          OnChangeText(sender, e);
      }
  } 
  </code></pre>
  
  <p>Presenter</p>
  
  <pre><code>class UserPresenter
  {       
      private void WireUpEvents()
      {
          _View.OnChangeText += new EventHandler(_View_OnChangeText);
      }
  
      private void _View_OnChangeText(object sender, EventArgs e)
      {
          ShowMatchingUsers();
      }
  
      private void ShowMatchingUsers()
      {
          var userList = _DataService.GetUsers(_View.UserName ); //edit
          _Veiew.UserList = userList; //edit
      }
  }
  </code></pre>
  
  <p>DataService</p>
  
  <pre><code>    public IEnumerable&lt;User&gt; GetUsers(string userID)
      { 
          string selectStatement = "SELECT user_id from [user] WHERE user_id like '@userID %'";
          List&lt;User&gt; UserList = new List&lt;User&gt;();
  
          using (var sqlConnection = new SqlConnection(db.ConnectionString))
  
          using (var sqlCommand = new SqlCommand(selectStatement, sqlConnection))
          {
              sqlCommand.Parameters.Add("@userID", SqlDbType.VarChar).Value = userID ;
              sqlConnection.Open();
  
              using (SqlDataReader dataReader = sqlCommand.ExecuteReader())
  
                  while (dataReader.Read())
                  {
                      UserList.Add(
                      new User 
                      {
                          UserID = (string) dataReader["user_id"]
                      });
                  }
  
              return UserList;
  
          }
      }
  </code></pre>