Member Avatar for gefen2215

i have a form from all costumers and i also have all payments now i need a sum field for all payments from a DataGridView

ok do like this , for example your 2nd column of grid is you amount column , which you want to sum ,

dim mySum as integer
mySum = 0
for i = 0 to datagridview1.rows.count -1 
nySum = val(datagridview1.item(1,i).value.tostring) + mySum
Next

This will Sum all the rows of your grid.

Regards

Assuming that the datagridview is bound to a datatable, then you can use the DataTable.Compute method.

Dim total As Decimal = CDec(dt.Compute("Sum([Payments])", "True"))

Where "dt" is the name of the datatable. I assumed that the column name in the datatable for "paymenents" is "Paymenents".

commented: very nice one , i dont know about it before . +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.