This can be one possible solution. Create a class called
MusicFile
which has
FileName
and
Path
properties.
public class Song{
public string Path {get;set;}
public string SongName {get;set;}
}
Then create the music list by loading the folder which contains the music files assigning the Path and SongName(removed file path)
protected void Form_Load(object sender, EventArgs e) {
bindList();
}
private void bindList{
List<Song> songs = new List<song>();
songs.Add(new Song() { Path="C:\\Users\\Joel\\Music\\song.wav", SongName="song" } );
listBox1.DataSource = songs;
listBox1.DisplayMember = "SongName";
listBox1.ValueMember = "Path";
}
private void listBox1_SelectedIndexChanged(Object sender, System.EventArgs e)
{
string song = listBox1.SelectedValue.ToString();
}