Totaling Column

Smithbr

Member
Joined
Jun 3, 2003
Messages
15
I was wondering how I can find the total of a column in a datagrid and display it in a label. Any suggestions?
Thanks
 
I am not familiar with datagrids. So the names of datagrid events and properties are just wild guesses.

But on the algorithm side Id suggest something like:


Code:
Private Sub RecalculateGrandTotal (...) handles myGrid.TextCellChange

If (mSkiptRecalculate) Then
   exit sub
end if 
 Use the Class-private variable mSkipRecalculate to avoid
 permanent recalculation when the grid is filled

Dim aRow as Datagridrow
Dim cellValue as integer
Dim runningTotal as interger = 0

For each aRow in myGrid.Rows
  If aRow.Item("this").Text is nothing then
     cellvalue = 0
  else
   cellValue = CInt(aRow.Item("this").Text)
  end if
  runningTotal += cellValue
Next row

lblGrandTotal.Text = CStr(runningTotal)
End Sub
 
Back
Top