title: Hide empty row in combobox with C#
body: <p>I load data into combobox named <code>cbxTravail</code>. I have these lines that work fine but my problem is that I have some blank lines that I want to hide them or delete them from the list in combobox. </p>
  
  <pre><code>string myconnstrng = ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString;
  SqlConnection conn = new SqlConnection(myconnstrng);
  DataSet ds = new DataSet();
  
  try
  {
      conn.Open();
  
      SqlCommand cmd = new SqlCommand("select TeethWorkID,Travail from TeethWorkNamesTable group by TeethWorkID, Travail", conn);
  
      SqlDataAdapter da = new SqlDataAdapter();
      da.SelectCommand = cmd;
      da.Fill(ds);
  
      // ds.Tables.Clear();
      // adapter.Fill(ds);
      cbxTravail.DisplayMember = "Travail";
      cbxTravail.ValueMember = "TeethWorkID";
      cbxTravail.DataSource = ds.Tables[0];
  
      for (int i = cbxTravail.Items.Count - 1; i &gt;= 0; i += -1)
      {
          if (cbxTravail.GetItemText(cbxTravail.Items[i]) == string.Empty)
          {
              cbxTravail.Items.RemoveAt(i);
          }
      }
  }
  catch (Exception ex)
  {
      //Exception Message
  }
  finally
  {
      conn.Close();
      conn.Dispose();
  }
  </code></pre>
  
  <p>I add this line for delete blank items from list but it doesn't work.</p>
  
  <pre><code>for (int i = cbxTravail.Items.Count - 1; i &gt;= 0; i += -1)
  {
      if (cbxTravail.GetItemText(cbxTravail.Items[i]) == string.Empty)
      {
          cbxTravail.Items.RemoveAt(i);
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RFW5z.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RFW5z.jpg" alt="enter image description here"></a></p>