Click here to Skip to main content
16,004,678 members
Home / Discussions / C#
   

C#

 
GeneralRe: c#Move music files in listbox up or down Pin
Richard MacCutchan27-Oct-17 6:42
mveRichard MacCutchan27-Oct-17 6:42 
SuggestionRe: c#Move music files in listbox up or down Pin
Ralf Meier28-Oct-17 12:20
mveRalf Meier28-Oct-17 12:20 
GeneralRe: c#Move music files in listbox up or down Pin
Richard MacCutchan28-Oct-17 22:08
mveRichard MacCutchan28-Oct-17 22:08 
AnswerRe: c#Move music files in listbox up or down Pin
jschell27-Oct-17 7:39
jschell27-Oct-17 7:39 
AnswerRe: c#Move music files in listbox up or down Pin
Gerry Schmitz28-Oct-17 3:31
mveGerry Schmitz28-Oct-17 3:31 
Questionc# Need to be able to play music files that were additional items to the list box Pin
Member 1348924427-Oct-17 3:52
Member 1348924427-Oct-17 3:52 
AnswerRe: c# Need to be able to play music files that were additional items to the list box Pin
OriginalGriff27-Oct-17 3:57
mveOriginalGriff27-Oct-17 3:57 
AnswerRe: c# Need to be able to play music files that were additional items to the list box Pin
Richard Deeming27-Oct-17 4:04
mveRichard Deeming27-Oct-17 4:04 
You're appending the new files to the list, but replacing the paths variable with the new paths.

So, for example, if you've already selected files A, B and C:
List = { A, B, C }
Paths = { A, B, C }

and you then select D and E:
List = { A, B, C, D, E }
Paths = { D, E }

if you try to play A, you'll get D; if you try to play B, you'll get E; if you try to play anything else, you'll get an IndexOutOfRangeException.

If you want to replace the list of files, you'll need to call listBox1.Items.Clear() before adding the new files.

If you want to append the list of files, you'll need to append them to the paths list as well. The simplest option would probably be to change it to be a List<string> instead of an array:
C#
private readonly List<string> paths = new List<string>();

private void btnFiles_Click(object sender, EventArgs e)
{
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Multiselect = true;
    
    if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        paths.AddRange(openFileDialog1.FileNames);
        
        string[] files = openFileDialog1.SafeFileNames;
        for (int i = 0; i < files.Length; i++)
        {
            listBox1.Items.Add(files[i]);
        }
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralSOLVEDRe: c# Need to be able to play music files that were additional items to the list box Pin
Member 1348924427-Oct-17 4:18
Member 1348924427-Oct-17 4:18 
AnswerRe: c# Need to be able to play music files that were additional items to the list box Pin
Gerry Schmitz27-Oct-17 4:26
mveGerry Schmitz27-Oct-17 4:26 
QuestionExporting result to .csv format instead of .xlsx without using interop.excel Pin
Ratsr26-Oct-17 23:54
Ratsr26-Oct-17 23:54 
AnswerRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Ralf Meier27-Oct-17 0:21
mveRalf Meier27-Oct-17 0:21 
GeneralRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Ratsr27-Oct-17 0:30
Ratsr27-Oct-17 0:30 
SuggestionRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Ralf Meier27-Oct-17 0:39
mveRalf Meier27-Oct-17 0:39 
GeneralRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Ratsr27-Oct-17 0:48
Ratsr27-Oct-17 0:48 
AnswerRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Richard MacCutchan27-Oct-17 0:36
mveRichard MacCutchan27-Oct-17 0:36 
GeneralRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Jim_Snyder27-Oct-17 4:28
professionalJim_Snyder27-Oct-17 4:28 
GeneralRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Richard MacCutchan27-Oct-17 5:05
mveRichard MacCutchan27-Oct-17 5:05 
AnswerRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Richard Deeming27-Oct-17 1:15
mveRichard Deeming27-Oct-17 1:15 
GeneralRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Nathan Minier27-Oct-17 1:28
professionalNathan Minier27-Oct-17 1:28 
AnswerRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Jim_Snyder27-Oct-17 4:24
professionalJim_Snyder27-Oct-17 4:24 
AnswerRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Gerry Schmitz27-Oct-17 4:43
mveGerry Schmitz27-Oct-17 4:43 
GeneralRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Richard MacCutchan27-Oct-17 5:06
mveRichard MacCutchan27-Oct-17 5:06 
QuestionProgram crashes when form is refreshed Pin
Member 1274878324-Oct-17 11:55
Member 1274878324-Oct-17 11:55 
AnswerRe: Program crashes when form is refreshed Pin
Dave Kreskowiak24-Oct-17 12:08
mveDave Kreskowiak24-Oct-17 12:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.