Ako Musha

Ako Musha

  • NA
  • 28
  • 12.2k

How to do Loop to calculate the cell values in DataGridView?

Sep 27 2018 4:00 PM
Hello ..
 
How to multiply a value of a row of a column to all the values in another column and do the loop for all rows.Then, at the end, sum the values in each row?
 
Thanks so much for your help!!
 
Here is an example.
  
C 1 C2 C3
40 1 40
30 2 110
20 3 200
10   140
   
80
30
 
Please note that I do not want to have or show these three columns (I, II, III) in my table. but I just put them in here to show the steps. Column 2 could have lots of rows...
 
Here is what I have done...
 
The loop works only for the 1st two rows in Column 3..!!? I can not figure it out! Thanks a lot for your help!
 
Dim i As Integer
For k As Integer = 0 To Data1.ColumnCount - 4
For j = 0 to Data1.Rows.Count - 2
Data1.Rows(j).Cells(2).Value = Data1.Rows(j).Cells(0).Value * Data1.Rows(j).Cells(1).Value
For i = 0 To EOF()
i = i + 1
Data1.Rows(j).Cells(3).Value = Data1.Rows(j).Cells(0).Value * Data1.Rows(k+i).Cells(1).Value + Data1.Rows(j).Cells(2).Value
Next i
Next j
Next k

Answers (5)