what does "Attempted to access cell -1,1 but limit is -1,2" mean

Everything was working fine, then I made a temporary change to the column sizes in the inspector of a list box. That worked fine. Then after changing the columns back to the original I am getting this OutOfBounds exception when DeleteAllRows is called on the list box. I don’t think I chnaged anything else. I have three columns. Widths are set to 131,1,1.

If I knew what “Attempted to access cell -1,1 but limit is -1,2” meant, maybe I can find what I did to cause the problem.

Thanks,

John

You access a cell, but the listbox is empty?

No. The list box in fact has 4 rows.

I tried doing a while loop removing row 0 until the list box was empty and it failed on the first row.

Maybe you check if it breaks at the breakpoint to look what method you call with what parameters?

I found the problem.

The problem was in the SelectioinChanged event of the list box. I have an if statement that tests if the seelected row is not -1 then performs some stuff with the selected row. I had accedentallly moved a line of that code that was accessing a cell in the selected row outside of the if statement. So it was trying to access a cell in row -1 after all the rows had beed deleted.

It’s not helpful that the error in the debugger is thrown at the delete all line and not in the selectionchanged event where the actual error occurs.

The error kind of makes sense. "Attempted to access cell -1,1…) is accurate, but what does “…, but limit is -1,2” mean?

In any event, problem solved. Christian, thanks for trying to help.

John

I guess that’s the possible range for your listbox at that time. You said you included 3 columns, so the possible cell range is (-1, 0) to (-1, 2) – which of course means “no cell in all columns”.

@Ulrich Bogun which of course means “no cell in all columns”.

It took a while but I think I get it now. I was reading “limit” to be the bounds of the list box, which I should have known was not the case given that -1 is not a row and out of bounds would have to be -2. If I think of “Limit” as referring to the current dimensions of the list box, not the bounds, it makes sense to me. So -1,2 means zero rows and 3 columns, 0,2 would be 1 row 3 columns.

I suppose bounds is the same thing as dimensions, but I was not thinking that way as -1 is OUT of bounds.

Got it! Thanks Ulrich.

John