I have a list box, with an item "Math". When I click on the Math item, I want a new collection of items to be added to the listbox after removing the current Math item, and make a back button to appear to return Math item back in case I need to go back. I was able to do that, but after I click on the back button and click on the Math item again, the previous collection of items is added to the previously added collection, so I get repeats. I can't figure out how to clear the "MathDep" - previous collection of items before importing the collection of items again. Here is the code I have:
Private Sub ListBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseClick
If Me.ListBox1.SelectedItem = "Math" Then
BackButton.Visible = True
'Clears the current item - "Math"
ListBox1.Items.Clear()
'Which Items to add
MathDep.AddRange(New String() {"Boo, Ashka", "Reffo, James", "Eldin, Carl", "Utkin, Boris"})
'Adds the new collection of items
Dim str As String
For Each str In MathDep
ListBox1.Items.Add(str)
Next
End If
End Sub
Private Sub BackButton_Click(sender As Object, e As EventArgs) Handles BackButton.Click
If RB_Department_4.Checked = True Then
ListBox1.Items.Clear()
'The listbox has the Math item back
For Each item As String In My.Settings.DepartmentCollection
ListBox1.Items.Add(item)
Next
BackButton.Visible = False
End If
End Sub