复选框中的DataGridView列计数增量和判别?

时间:2015-11-30 19:47:07

标签: vb.net checkbox datagridview

我想只计算一个复选框,向学生展示我有一个单独的创建功能(单元格7复选框)选中并取消选中,下面是一个标签,以显示已签入的复选框。 :(

Friend Function Re_chk(ByRef Dgv1 As DataGridView) As Boolean
    Re_chk = False
    Try
        Dim count1 As Integer = 1
        For Each row As DataGridViewRow In Dgv1.Rows
            If row.Cells(7).Value = True Then
                count1 += 1
            End If
        Next
        Student_Details.LblAttendceCont.Text = count1
        Re_chk = True
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Function

http://i.stack.imgur.com/aMqiO.png

1 个答案:

答案 0 :(得分:0)

Friend Function Re_chk(ByRef Dgv1 As DataGridView) As Integer
Try
    Dim count1 As Integer = 0
    For Each row As DataGridViewRow In Dgv1.Rows
        If row.Cells(7).Value = True Then
            count1 += 1
        End If
    Next
    Re_chk = count1
Catch ex As Exception
    Re_chk = 0
End Try
End Function

在您的代码中调用此函数如下: -

Dim checkCounter as Integer
checkCounter = Re_chk(Dgv1)
Student_Details.LblAttendceCont.Text = checkCounter