Arrays in C# are zero based, and so the only valid values you can use for an index has to be between
0
and
(N - 1)
where
N
is the number of items in the array. Any other value (i.e. negative, or greater-than-or-equal to
N
) will give you an "index out of range" exception.
So for an array with three elements, the only valoid index values are
0
,
1
, and
2
.
We don't know exactly where your index error is being thrown, but I suggest that this line might be relevant:
if (e.ColumnIndex == 0 & e.Value != null)
&
is a binary AND operator, not the logical AND which is
&&
Binary AND compares bits in a number, and returns all the bits that are the same.
Logical AND compares boolean values, and returns
true
if and only if both parameters are
true
.