Hi!!
I have piece of code that gets all the files from a folder and adds their path to a List. Then I have a loop that loops through the list and adds the filenames to Listbox.
(FicheirosMusicas is the Listbox)Code:Dim FilesMusicas As New List(Of String) FilesMusicas.AddRange(IO.Directory.GetFiles("C:\MyPath", "*.*mp3")) For a As Integer = 0 To FilesMusicas.Count - 1 FicheirosMusicas.Items.Add(IO.Path.GetFileNameWithoutExtension(FilesMusicas(a))) Next
Now my problem is that I want to remove multiple items from the Listbox but at the same time the correpondent items on the List. i have this code that should work, but eveytime i run it, it gives me the error "Index was outside the bounds of the array." on the FilesMusicas.RemoveAt(.SelectedIndices(0)) line.
Why does this happen?Code:With FicheirosMusicas .BeginUpdate() While .SelectedIndices.Count > 0 .Items.RemoveAt(.SelectedIndices(0)) FilesMusicas.RemoveAt(.SelectedIndices(0)) End While .EndUpdate() End With




Reply With Quote