title: How to delete object from combobox?
body: <p>I have a combobox with objects of <code>Foo</code> type, here is the <code>Foo</code> class:</p>
  
  <pre><code>public class Foo
  {
      public string name { get; set; }
      public string path { get; set; }
  }
  </code></pre>
  
  <p>The <code>Foo.name</code> is the displayed text in the combobox and <code>Foo.path</code> is the value of the selected option.</p>
  
  <p>I want to delete an option from the combobox after some operation I made. </p>
  
  <p>I've tried these ways:</p>
  
  <ul>
  <li><p>1</p>
  
  <pre><code>comboBox2.Items.Remove(@comboBox2.Text);  
  </code></pre></li>
  <li><p>2</p>
  
  <pre><code>comboBox2.Items.Remove(@comboBox2.SelectedValue.ToString());  
  </code></pre></li>
  <li><p>3</p>
  
  <pre><code>Foo ToDelete = new Foo();
  ToDelete.name = @comboBox2.Text;
  ToDelete.path = @comboBox2.SelectedValue.ToString();
  comboBox2.Items.Remove(ToDelete); 
  </code></pre></li>
  </ul>
  
  <p>Nothing works for me. : / How to do this?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is how I'm initializing my combobox:</p>
  
  <pre><code>    string[] filePaths = Directory.GetFiles(sites.paths[comboBox1.SelectedIndex]);
  
          List&lt;Foo&gt; combo2data = new List&lt;Foo&gt;();
  
          foreach (string s in filePaths)
          {
              Foo fileInsert = new Foo();
              fileInsert.path = s;
              fileInsert.name = Path.GetFileName(s);
              combo2data.Add(fileInsert);
          }
  
          comboBox2.DataSource = combo2data;
          comboBox2.ValueMember = "path";
          comboBox2.DisplayMember = "name";
  </code></pre>