tags:

views:

629

answers:

6
+1  A: 

How is rowsDisplayStatus populated? If it only contains one element and something is expected to be at index 9, you should take a look at the code that populates it.

Dustin Campbell
A: 

As the picture shows, rowsDisplayStatus has 1 item in it... you're trying to pull the 10th item (or the item at index 9)... that index is out of range.

blesh
+1  A: 

You're getting the row index and then trying to use it with rowsDisplayStatus. You can't use the database row index as an index into your collections.

I would change:

if (!rowsDisplayStatus[rowIndex])

to:

if (!rowsDisplayStatus[i])
Mark Ingram
thanks Mark, that did the trick.
A: 

How is "rowsDisplayStatus" populated? Maybe there is a problem in that routine.

shanabus
A: 

I'll explain what mark said, above. (Don't know how to comment, so putting this in an answer) He's correct you should change the

if (!rowsDisplayStatus[rowIndex])

Into

if (!rowsDisplayStatus[i])

The reason for this is as follows:

The rowIndex grows even when rows where previously deleted from the Rows object. So there could be only one or two rows in the dr.Table.Rows, but they could have indexes (indice) for example of 8 and 9 (because previously rows 1 to 7 where erased or for other reasons).

So you get the current rowIndex by checking the bindingManager.Current.RowIndex property.

But your rowsDisplayStatus is a simple array (or ArrayList) with the correct amount of rows according to i. So for row index:8 (the first row) you should look at rowsDisplayStatus[0] (which is the value of i), and for row index:9 (the second row) you should look at rowsDisplayStatus[1]... etc.

HTH, Moshe

pashute
A: 

Basically, whenever I've received this error the index (or value that I have set) was non-existant at the time it was being referenced.

For example if I have two Items in a ListBox and I tryi to reference a third Item, I will receive an Index Out Of Range exception (many times in the past)...

baeltazor