title: Removing duplicate items (string) from listBox
body: <p>I'm a university student doing a project for a unit. We're creating a web application dashboard, and I can't seem to remove duplicates from a listBox (customerNameListBox). </p>
  
  <pre><code>public partial class Graphs : System.Web.UI.MasterPage
      {
          string FullDataCSV = Path.Combine(HttpContext.Current.Server.MapPath
      ("~/App_Data/Full_Data.csv"));
  
      List&lt;CSVEntry&gt; CSVList = new List&lt;CSVEntry&gt;();
  
      public void ReadFile()
      {
          try
          {
              StreamReader inputFile; 
              string line;            
              CSVEntry entry = new CSVEntry();
              char[] delim = { ',' };
              inputFile = File.OpenText(FullDataCSV);
  
              while (!inputFile.EndOfStream)
              {
                  line = inputFile.ReadLine();
                  string[] tokens = line.Split(delim);
                  entry.Value0 = tokens[0];       
                  entry.customerName = tokens[22];        
                  entry.Value29 = tokens[29];
  
                  CSVList.Add(entry);
              }
          }
          catch
          {
              Response.Redirect("Error.aspx");
          }
      }
  
      private void DisplayCustomerName()
      {
          foreach (CSVEntry entry in CSVList)
          {
              customerNameListBox.Items.Add(entry.customerName);
          }
      }
  
      private void SortCustomerName()
      {
          CSVList = CSVList.OrderBy(x =&gt; x.customerName).ToList();
      }
  
      protected void Page_Load(object sender, EventArgs e)
      {
          ReadFile();
          SortCustomerName();
          DisplayCustomerName();
      }
  
      protected void historyButton_Click(object sender, EventArgs e)
      {
          Response.Redirect("History.aspx");
      }
  
      protected void exportButton_Click(object sender, EventArgs e)
      {
          Response.Redirect("Export.aspx");
      }
  
      protected void printButton_Click(object sender, EventArgs e)
      {
          Response.Redirect("Print.aspx");
      }
  }
  </code></pre>
  
  <p>I have tried using the below code to remove the duplicate items in the customerNameTextBox, but it's not working at all. </p>
  
  <pre><code>protected void goButton_Click(object sender, EventArgs e)
      {
          List&lt;string&gt; removals = new List&lt;string&gt;();
          foreach (string s in customerNameListBox.Items)
          {
              removals.Add(s);
          }
  
          foreach (string s in removals)
          {
              customerNameListBox.Items.Remove(s);
          }
  </code></pre>