Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Assign different values ​to a string using a for

I have the following structure for

for (int i = 0; i < lstArquivosRetorno.Items.Count; i++)
{
    lstArquivosRetorno.SetSelected(i, true);

    string nomeArquivo = string.Format(
      "{0}{1}", 
       Funcoes.IncludeBackSlash(edtPathArquivo.Text),
       lstArquivosRetorno.SelectedItem.ToString());

    _relacaoArquivos.Add(nomeArquivo);
}

What I’m doing is the following: I have a List<string> _relacaoArquivos and I add the filename to that list using that structure, however, if I have more than one file selected, it only stores and adds the first file.

How can I go through my for structure to store and add the names of all files to the list?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

lstArquivosRetorno looks like a select list or similar. When creating the nomeArquivo string, the SelectedItem is being used to create the string. That is why you’re getting only one item added to the _relacaoArquivos list.

lstArquivosRetorno.SelectedItem should be lstArquivosRetorno.Items[i]

string nomeArquivo = string.Format(
      "{0}{1}", 
       Funcoes.IncludeBackSlash(edtPathArquivo.Text),
       lstArquivosRetorno.Items[i]); // no need to call ToString()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading