So this "next song" button code has been working for a while and it recently stopped working. It's highlighting the next song but keeping the current song highlighted so it just played from the beginning of the selected index. Here is the next song code:
private void nSong_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex < listBox1.Items.Count - 1)
{
listBox1.SelectedIndex = listBox1.SelectedIndex + 1;
WMPPlayer.URL = filepaths[listBox1.SelectedIndex];
}
}
I'm thinking it has something to do with the "SelectedIndex + 1" part of it because it's making the selected index two songs instead of one. Strangely enough, if you click it again it keeps it at two selected instead of going to three or more. Are there any tips you guys have on where I'm going wrong?
Thanks in advance
It seems as though you have the selection mode of the listbox wrongly configured. To set it to single selection mode use:
new ListBox().SelectionMode = SelectionMode.One;
This makes it impossible to select multiple items.
However, if you still want it to be possible to select multiple items, you can clear the selection before:
new ListBox().ClearSelected();
If this still doesn't work the problem isn't located in the snippet you provided - therefore we'd need to see more code.
I hope I could help you.