I have a toolstripbutton that contains this code:
Dim total, tXS, tS, tM, tL, tXL As Integer
For i = 0 To dvJOBranch.Rows.Count - 1
tXS += dvJOBranch.Rows(i).Cells("XS").Value
tS += dvJOBranch.Rows(i).Cells("S").Value
tM += dvJOBranch.Rows(i).Cells("M").Value
tL += dvJOBranch.Rows(i).Cells("L").Value
tXL += dvJOBranch.Rows(i).Cells("XL").Value
Next
total = tXS + tS + tM + tL + tXL
MsgBox(total)
Its only works once, like for example, if my datagridview cell contains all zeros, the total is zero, and then when I input numbers in the first row of the columns(for example I input 5), the total is zero again.
But if I put this code in a button, it works fine.
Thank you.
If you mean by
total
is a Label .. then you may put your code in yourdatagridview_cellvalidated
event ..In your ToolStripButton put the code
Msgbox(total)