如何计算DGV中的TOTAL [英] How To Calculate TOTAL in DGV
问题描述
嗨..所有如何计算总数...我期待这个输出
Regno名称等级Jan Feb Mar Apr TOTAL
A100 AAA I 500 150 120 54 824
A200 BBB I 450 50 0 0 500
请告诉我..我怎么做..
我在这里使用这个代码
对于 j1 作为 整数 = 0 DataGridView1.Rows.Count - 1
对于 ij 作为 整数 = 3 DataGridView1.Columns.Count - 1
使用 我 .DataGridVie w1.Rows.GetFirstRow( Me .DataGridView1.Rows.Count - 1 )
If IsDBNull(DataGridView1(ij,j1).Value)<> True 然后
total = total + DataGridView1(ij,j1).Value
结束 如果
结束 使用
下一步 ij
DataGridView1.Rows(j1).Cells ( TOTAL)。值=总计
下一步 j1
现在这个代码显示如此输出
Regno名称类Jan Feb Mar Apr TOTAL
A100 AAA I 500 150 120 54 824
A200 BBB I 450 50 0 0 1324
< blockquote>如果你使用Sql Query将数据与数据绑定,那么最好只在查询端对它进行总结。
SELECT RegNo,Name,Class,Jan,Feb,Mar,Apr,(Jan + Feb + Mar + Apr)as FROM FROM TABLE
快乐编码:)
DataGridView1.Rows(j1).Cells( TOTAL)。值=总计
之后把
total = 0
Hi.. All How To Calculate Total.. I Expect This OUTPUT
Regno Name Class Jan Feb Mar Apr TOTAL
A100 AAA I 500 150 120 54 824
A200 BBB I 450 50 0 0 500
Please Tell me.. how to i do..
Here I am Using This CODE
For j1 As Integer = 0 To DataGridView1.Rows.Count - 1
For ij As Integer = 3 To DataGridView1.Columns.Count - 1
With Me.DataGridView1.Rows.GetFirstRow(Me.DataGridView1.Rows.Count - 1)
If IsDBNull(DataGridView1(ij, j1).Value) <> True Then
total = total + DataGridView1(ij, j1).Value
End If
End With
Next ij
DataGridView1.Rows(j1).Cells("TOTAL").Value = total
Next j1
Now This CODE SHOW LIKE THIS OUTPUT
Regno Name Class Jan Feb Mar Apr TOTAL
A100 AAA I 500 150 120 54 824
A200 BBB I 450 50 0 0 1324
If you are binding the grid with data using Sql Query then its better to sum up there on query side only likewise
SELECT RegNo , Name , Class , Jan , Feb , Mar , Apr ,(Jan+Feb+Mar+Apr) as Total FROM TABLE
happy coding :)
DataGridView1.Rows(j1).Cells("TOTAL").Value = total
After that put
total=0
这篇关于如何计算DGV中的TOTAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!