Sum Total datagridview1列(HH:mm)VB 2010

时间:2014-11-19 03:00:42

标签: vb.net datagridview

大家好,请帮帮我.. 我有一个datagridview,他的数据来自我上传的excel文件。 问题在于总小时(工时 - HH:mm)这是我的代码

 Private Sub Hitung()
    Dim jamkerja As Short
    jamkerja = 0
    For t As Integer = 0 To DGVexcel.Rows.Count - 1
        jamkerja = jamkerja + Val(DGVexcel.Rows(t).Cells(7).Value)
    Next
    txtjamkerja.Text = jamkerja
End Sub

请帮助我将小时和分钟的总价值放入TEXTBOX 看到这张图片:enter image description here

1 个答案:

答案 0 :(得分:0)

快速而肮脏的方法是在将值添加到时间跨度对象时循环遍历每个项目。 (见:http://www.dotnetperls.com/timespan

Private Sub Hitung()
    Dim jamkerja As Short
    Dim timespan As new TimeSpan(0, 0, 0, 0, 0)
    jamkerja = 0
    For t As Integer = 0 To DGVexcel.Rows.Count - 1
        'jamkerja = jamkerja + Val(DGVexcel.Rows(t).Cells(7).Value)

        Dim value = Val(DGVexcel.Rows(t).Cells(7).Value)         

        Dim interval As TimeSpan
        If Not TimeSpan.TryParse(value, interval)

           timespan.Add(interval)
        End If
    Next
    txtjamkerja.Text = timespan.ToString()
End Sub