Assigning ListBox values to vector

0

When you play the items one by one within a vector, position 0 with 0, and so on, works correctly. But the code shows a malfunction because, in the first iteration goes normal in the second of the error:

  

InvalidArgument = Value of '1' is not valid for 'index'.   This is true that position 1 is not index, but I am not wanting to select the index of the list.

for (j = 0; j <= notas_operacao; j++)   <== quantidade de notas no listbox
            {
                foreach (var item in listBox_Nfe.Items) <==== corre listBox
                {
                    notas[j] = listBox_Nfe.Items[j].ToString(); <==deveria jogar list item atual em posição de vetor em j
                    MessageBox.Show(notas[j]); => debug
                }
            }
    
asked by anonymous 15.01.2015 / 17:33

1 answer

2

This is what you intend:

foreach (var item in listBox_Nfe.Items) <==== corre listBox
{
    int j = 0;
    notas[j] = item.ToString();
    MessageBox.Show(notas[j]);
    j++;
}

The information you give is not much, so I may be wrong.

    
15.01.2015 / 17:46