Why it didn't change the value during for each?

I met a problem that I’m using for each to loop my DataRow.
During the loop, it’ll assign Date when it sees the specific value.
I knew that it shouldn’t use “item” as a target to assign, it should use DataRow with the index of ItemArray instead.

But whenever I tried, the value still the same.

Could anyone tell me the reason and how to solve the problem?

Thanks in advance!


Hi, does the ColIndex value is static or dynamic because i can’t see it in the example. If i understand correctly you are always filling last row in the table isn’t it ? What value are not filled then ?

Hi @rado
The ColIndex is dynamic that I set it from the properties of “For Each” the output value.

I checked it is incremental.


Then can you share with us what values stay constant ? Lets say that row has 10 columns, are you having same data in whole colums ? Is that row is already empty or it has some data ? Share more details.

It’s a summary file that it has over 100 columns and the last row are the information of SUM value of each column.

I used for each to get rid of the empty columns that some of them are not amount, but other content.

And the last thing I’m doing at the present is just one cell that I need to change a value of cell “Total” to the “Date” the file released.

The cell of “Total” is in the Column Index 0. Even I tries to assign it directly “TestDT.Rows(TestDT.Rows.Count - 1).ItemArray(0) = 20190910”, it still shows me “Total”.

I tried to use “For each Row” instead of “For each” which makes me feel weird and wrong. But it could change the value when I assign it.
But still don’t understand why the “for each row” can achieve it, but “for each” can’t.

I want to know the reason or probably what detail i didn’t notice.



Before we do anything, is it possible to check what value is under the TestDT.Rows(TestDT.Rows.Count - 1).ItemArray(0) before you are trying to assign new value ?


Yes, I checked and it is “Total” inside the cell no doubt.
And after assign, it still the same.


Please check, maybe it is read only.

Hi @rado
it’ not read only.

Otherwise, it’s work when using “For each row” to assign value replace the “Total”.
I don’t know why “For each” can’t do the same thing like this.


Hard to say why it does working with For Each Row, maybe definition of the For each object is wrong :(, can you share it to check ?