I have a problem on my music player C# application, If I add new files using open file dialogue. The array is not adding the new files. Then it will show the Selected Index Array Index out of bound exception error on player.URL = path[track_list.SelectedIndex];
on the following line. So how to handle this exception ? How to update the new elements on the array ?
string[] files, path;
private void Track_list_SelectedIndexChanged(object sender, EventArgs e)
{
player.URL = path[track_list.SelectedIndex];
}
private void Btn_import_Click_1(object sender, EventArgs e)
{
//ofd is the instance of open file dialogue
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
//add the file name into two arrays
files = ofd.SafeFileNames;
path = ofd.FileNames;
for (int i=0; i<files.Length; i++)
{
//add songs into the items box
track_list.Items.Add(files[i]);
}
}
}