Reading first Item from asp.net ListBox

  • Thread starter Thread starter Robert Smit
  • Start date Start date
R

Robert Smit

I have the following problem:

If I run this code:

dagCap1.berekenDagCapaciteit(ref lbOrderDag1);

I get the error that I can't read the first row from the ListBox.

System.IndexOutOfRangeException: There is no row at position 0

this is the function I use:

public void berekenDagCapaciteit(ref ListBox lbDag)
{


double tempOrderTime = 0.0d;


for (int i = 0; i < lbDag.Items.Count; i++)
{
string orderNr = Convert.ToString(lbDag.Items);
uitvoerenQuery(orderNr);
tempOrderTime = (aantal * runTime) + setupTime;

totaalOrderTime += tempOrderTime;
totaalFreeTime = dagCap - totaalOrderTime;

}
}

When I try to acces the first row when I don't use the for loop for
example like this: r = Convert.ToString(lbDag.Items[0]); The first
item does have a value. I can't find out what's wrong. Has it
something to do with the loop?

Who can help me out,

Robert Smit
 
*When* you do this also matters. Make sure its after all items have been added before you do this operation. Do a check (this.ListBox1.Items.Count must be greater than 0)
 
Back
Top