0

I'm making an Mp3 player in Visual Basic. It was all going well till I decided I wanted a "Recent plays" list. I want it to be able to save and load multible items.

I'm not getting any errors with my code, it just adds some kind of collection to the list. Here is the relevant code:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    ListBox1.Items.Add(My.Settings.Recent)
End Sub

Private Sub Label6_Click(sender As Object, e As EventArgs) Handles Label6.Click
    If Label6.Text = "Play" Then
        My.Settings.Recent.Add(OpenFileDialog1.FileName.ToString)
        ListBox1.Items.Add(My.Settings.Recent)
        My.Settings.Save()
        WindowsMediaPlayer1.URL = Label5.Text
        WindowsMediaPlayer1.Ctlcontrols.play()
        Label6.Text = "Pause"
    End If
End Sub

If you want to see more code just ask.

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
Adam Films
  • 11
  • 6

1 Answers1

0

You are doing it wrong. This:

ListBox1.Items.Add(My.Settings.Recent)

will only add one item (it likely implicitly converts the property to a string, which is probably why you get no error).

This would be the correct way:

ListBox1.Items.AddRange(My.Settings.Recent)

Also don't forget to clear your ListBox before adding the entire collection again:

ListBox1.Items.Clear()
ListBox1.Items.AddRange(My.Settings.Recent)
Visual Vincent
  • 18,045
  • 5
  • 28
  • 75