Datagridview复选框 [英] Datagridview Check Box

查看:104
本文介绍了Datagridview复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编码...如果选中了无记录"复选框,那么它们仍会合计在内.例如,在工作周中,有5人参加了上课,但只有3个人有数据并且没有记录的复选框被选中,因此保留为(1/5) * 100,而不是1/3

Im trying to code...that if the no records check box is checked  then they still count in the total..for examply in mid wk call 5 people attended class but only 3 peopple have data and the check box with no records is checked therefore is shold be (1/5) * 100 instead of 1/3

   Private Sub dgvRecords_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

        If e.ColumnIndex = 1 Then
            Dim IsChecked As Boolean = False
            IsChecked = CBool(DirectCast(DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells("No Records"), DataGridViewCheckBoxCell).EditedFormattedValue)
            If IsChecked Then
                If MessageBoxButtons.YesNo Then
                    If MsgBox("Did this person attend?", MsgBoxStyle.YesNo, "Attendance") = MsgBoxResult.Yes Then
                    Else
                        DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells("Att. (Y/N)").Value = "N"
                    End If
                End If



 Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit

Dim countAtt As Integer = 0
        Dim countAtt2 As Integer = 0
        For Each a As DataRow In myTable.Rows
            Dim YesNo As String = a.Item("Att. (Y/N)").ToString.ToUpper
            If YesNo = "Y" Then countAtt += 1
            If YesNo = "N" Then countAtt2 += 1
        Next
        Me.txtAttendance.Text = Math.Round(((countAtt) / (countAtt + countAtt2)) * 100, 2).ToString() & "%"

        Dim countCall1 = 0
        Dim countCall2 = 0
        For Each r As DataRow In myTable.Rows
            Dim YesNo As String = r.Item("Mid. Wk. Call (Y/N)").ToString.ToUpper
            If YesNo = "Y" Then countCall1 += 1
            If YesNo = "N" Then countCall2 += 1
        Next
        Me.txtPhonecall.Text = Math.Round((countCall1 / (countCall1 + countCall2)) * 100, 2).ToString() & "%"

推荐答案

已选中"是什么意思?


这篇关于Datagridview复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆