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?
CodePudding user response:
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()