Basically I'm making a jukebox and I have a big problem with the WMPLib library.
I am trying to remove an item from the playlist , but the problem is that I can't find any way to get the index or the actual media by name.
I
was thinking of making a replica array of the playlist , but that is just stupidly more work then what I should put into a simple task like that.
private void queue_listbox_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (queue_listbox.SelectedItem != null)
{
wplayer.currentPlaylist.removeItem('Insert code here');
music_listbox.Items.Add(queue_listbox.SelectedItem);
queue_listbox.Items.Remove(queue_listbox.SelectedItem);
}
}
Just use a
Dictionary<TKey, TValue>like so:And then you can remove it by doing (pseudo code)
Dictionaries are pretty much lists, which are pretty much arrays, except, instead of passing a number as an indexer (
songs[5]gets the 6th song) you can pass whatever typeTKeyis (songs["Look at this Photograph"]gets the song that is paired with that string).I don't know if you made that
Listboxclass or if it's built by Microsoft. If it is built, thenItemsis can't be made a dictionary if it's already an array, in which case, you'll need to get more creative. You might have to basically recreateListboxjust to have theDictionaryor some clever workaround.You could do something like making a
ListboxManagerwhich would hold aDictionary<Listbox, Dictionary<string, Song>>and use an extension method calledGetItems(this Listbox listbox) => ListBoxManager.Listboxes[listbox];which would probably work.