Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

datagridview arithmatic operation

$
0
0
i have a form with datagridview like picture below :

Posted Image

in calculate button, i use this code :

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim total1, total2 As Double

        For i As Integer = 0 To DataGridView1.Rows.Count - 1

            total1 += DataGridView1.Rows(i).Cells(0).Value

            DataGridView1.Rows(i).Cells(3).Value = DataGridView1.Rows(i).Cells(1).Value * DataGridView1.Rows(i).Cells(2).Value / total1

            total2 += DataGridView1.Rows(i).Cells(3).Value

        Next

        TextBox1.Text = total2

    End Sub
End Class



problem is, this formula
DataGridView1.Rows(i).Cells(3).Value = DataGridView1.Rows(i).Cells(1).Value * DataGridView1.Rows(i).Cells(2).Value / total1
is only working for the last row with correct calculation, can anyone help please?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>