1

我们目前正在对学生的出勤情况进行监控,我们想计算每个学生在场和缺席的总天数。

     Subject LN  FN    MI  05/21/14   05/20/14   05/21/14 05/22/14  05/23/14  P  A

     Comp101 Yu Erick   C   (checked|(unchecked)|(checked)|(checked)|(checked)|4 | 1

“这就是我们想做的,但不是横向计数,而是纵向计数。有没有人可以帮助我们解决这个问题?

4

4 回答 4

1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles Button1.Click
Dim Present As Integer = 0
Dim Absent As Integer = 0
For a = 0 To DataGridView1.RowCount - 1
    For b = 0 To DataGridView1.ColumnCount - 8
        If DataGridView1.Rows(a).Cells(b + 5).Value = True Then
            Present += 1
        Else
            Absent += 1
        End If
    Next
    DataGridView1.Rows(a).Cells(10).Value =  Present 
    DataGridView1.Rows(a).Cells(11).Value =  Absent
    Present = 0
    Absent = 0
Next
End Sub

试试这个 ....

于 2014-05-21T02:46:54.887 回答
0

我想这就是你想要的...

在此处输入图像描述

此代码实际上检查每个包含 Checkbox 或 DatePresented 的单元格

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim count As Integer = 0
    For a = 0 To DataGridView1.RowCount - 1
        For b = 0 To DataGridView1.ColumnCount - 2
            If DataGridView1.Rows(a).Cells(b + 1).Value = True Then
                count += 1
            End If
        Next
        DataGridView1.Rows(a).Cells(6).Value = count
        count = 0
    Next
End Sub
于 2014-05-19T02:15:46.120 回答
0

在此处输入图像描述

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim count As Integer = 0
    For a = 0 To DataGridView1.RowCount - 1
        For b = 0 To DataGridView1.ColumnCount - 6
            If DataGridView1.Rows(a).Cells(b + 5).Value = True Then
                count += 1
            End If
        Next
        DataGridView1.Rows(a).Cells(4).Value = count
        count = 0
    Next
End Sub

将出勤列留空,因为将在此处插入总计...

Wew,我认为它解决了你的问题 =D

于 2014-05-20T08:54:28.413 回答
0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Present As Integer = 0
Dim Absent As Integer = 0
For a = 0 To DataGridView1.RowCount - 1
    For b = 0 To DataGridView1.ColumnCount - 6
        If DataGridView1.Rows(a).Cells(b + 5).Value = True Then
            Present += 1
        Else
            Absent += 1
        End If
    Next
    DataGridView1.Rows(a).Cells(4).Value = "Present: " & Present & " Absent: " & Absent
    Present = 0
    Absent = 0
Next
End Sub

好了,到这里就全部搞定了……

于 2014-05-21T01:25:03.693 回答