title: Remove items from a listbox if it appears in another
body: <p>I have 2 listbox's on my form. The first populates from an array and displays files names that relate to the value of a Date Time picker. When that item is double clicked it moves over to the 2nd list box, clears from the 1st and the relevant files are transferred from one directory to another. The problem I have is that as the population is part of the load event once the application is closed and then re-opened the files names appear in both listbox's.</p>
  
  <p>Is there a way to say if the object appears in 1 textbox then it shouldn't appear in the other?</p>
  
  <p>I've tried the following but re-opening still displays the object in both</p>
  
  <pre><code> Dim item As Object
  
          For Each item In lstPlanned.Items
              If lstProgress.Contains(item) Then
                  lstPlanned.Items.Remove(item)
              End If
          Next
  </code></pre>
  
  <p>For the 2nd listbox I'm using the following to populate it</p>
  
  <pre><code>For Each Dir As String In System.IO.Directory.GetDirectories(aMailbox)
          Dim dirInfo As New System.IO.DirectoryInfo(Dir)
          lstProgress.Items.Add(dirInfo.Name)
  </code></pre>
  
  <p>Full Load code as follows</p>
  
  <pre><code>Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
      Dim loaddate As String = Calendar.Value.ToString("dd/MM/yy")
  
      ReDim AllDetail(0 To 0)
      numfiles = 0
  
  
      lstPlanned.Items.Clear()
  
  
     Dim allfiles = lynxin.GetFiles("*.txt")
      ReDim AllDetails(allfiles.Count)
  
      lstProgress.Items.Clear()
  
      lstPlanned.Items.Add("No Jobs Planned Today!")
      lstPlanned.Enabled = False
  
      For Each txtfi In (allfiles)
          Dim allLines() As String = File.ReadAllLines(txtfi.FullName)
  
          AllDetails(numfiles) = New FileDetail()
  
          AllDetails(numfiles).uPath = Microsoft.VisualBasic.Left((txtfi.FullName), Len(txtfi.FullName) - 4)
  
          AllDetails(numfiles).uFile = Path.GetFileNameWithoutExtension(txtfi.Name)
  
          Dim line = allLines.Where(Function(x) (x.StartsWith("unitname="))).SingleOrDefault()
          If line IsNot Nothing Then
              AllDetails(numfiles).uName = line.Split("="c)(1)
          End If
  
          line = allLines.Where(Function(x) (x.StartsWith("unitcode="))).SingleOrDefault()
          If line IsNot Nothing Then
              AllDetails(numfiles).uCode = line.Split("="c)(1)
          End If
  
          line = allLines.Where(Function(x) (x.StartsWith("opername="))).SingleOrDefault()
          If line IsNot Nothing Then
              AllDetails(numfiles).uOps = line.Split("="c)(1)
          End If
  
          line = allLines.Where(Function(x) (x.StartsWith("plandate="))).SingleOrDefault()
          If line IsNot Nothing Then
              AllDetails(numfiles).uPlan = line.Split("="c)(1)
          End If
  
          line = allLines.Where(Function(x) (x.StartsWith("cliecode="))).SingleOrDefault()
          If line IsNot Nothing Then
              AllDetails(numfiles).uClient = line.Split("="c)(1)
          End If
  
          If AllDetails(numfiles).uPlan = loaddate Then
  
              lstPlanned.Items.Remove("No Jobs Planned Today!")
              lstPlanned.Enabled = True
              lstPlanned.Items.Insert(0, AllDetails(numfiles).uName &amp; " - " &amp; AllDetails(numfiles).uCode &amp; " - " &amp; AllDetails(numfiles).uOps)
              numfiles = numfiles + 1
  
          End If
  
      Next
  
  
      For Each Dir As String In System.IO.Directory.GetDirectories(aMailbox)
          Dim dirInfo As New System.IO.DirectoryInfo(Dir)
          lstProgress.Items.Add(dirInfo.Name)
  
          Dim item As Object
  
          For Each item In lstPlanned.Items
              If lstProgress.Contains(item) Then
                  lstPlanned.Items.Remove(item)
              End If
          Next
      Next
  
     End Sub
  </code></pre>