0

I have looked around a couple of sites and found how to remove duplicates from a listbox but not how to send the duplicate free list of names over to a second listbox, an example of code i found

Private Sub ListBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Dim fd As New Dictionary(Of String, Integer)
        For Each filename As String In IO.Directory.GetFiles("c:\windows")
        Next
        For Each entry As KeyValuePair(Of String, Integer) In fd
            ListBox1.Items.Add(String.Format("{0} ({1})", entry.Key, entry.Value))
        Next
    End Sub
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Teme64
0

I'm not sure where you need Dictionary object, but if you want a list of unique file names, here's how I would do it

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  '
  Dim FileNames() As String
  Dim FileName As String
  
  FileNames = IO.Directory.GetFiles("c:\windows")
  For Each FileName In FileNames
    If ListBox1.Items.IndexOf(FileName) < 0 Then
      ListBox1.Items.Add(FileName)
    End If
  Next

End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.