1

We are currently doing a student monitoring attendance , and we want to count the total number of days each student is present and absent .

     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

"This is what we wanted to do but instead of counting horizontally it counts vertically.Is there anyone who can help us solving this problem?

Juri14
  • 13
  • 1
  • 1
  • 8
  • we cant tell you what is wrong with your code without seeing....your code. [Edit](http://stackoverflow.com/posts/23728412/edit) your post to show what you have tried. and how did [the answer last time](http://stackoverflow.com/q/23668834/1070452) not work? – Ňɏssa Pøngjǣrdenlarp May 19 '14 at 01:06
  • Is the Checked and Unchecked is a DataGridView CheckBox or just a String Value ? – GoroundoVipa May 19 '14 at 01:43
  • @Goroundo , It is a DataGridView checkBox – Juri14 May 19 '14 at 03:57
  • Ohhh okay, i post the answer for that. try it i hope it helps – GoroundoVipa May 19 '14 at 04:40
  • @GoroundoVipa , We edited our datagridview and we tried your code.But an error appeared , "Conversion from string "Yu" to type 'Boolean' is not valid." – Juri14 May 20 '14 at 07:12
  • Hmmm... it means that the Cell range is lost in condition to boolean, like the condition goes to the DataGridViewTextBox, can you explain your datagridview format like: first Col is DataGridViewTextBox, second to Sixth is DataGridViewCheckBox Then seventh is DataGridViewTextBox. – GoroundoVipa May 20 '14 at 08:01
  • @GoroundoVipa, Our first five column are DataGridViewTextBox and followed by eleven Columns of DatagridviewCheckBox . – Juri14 May 20 '14 at 08:19

4 Answers4

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

Try This ....

GoroundoVipa
  • 249
  • 3
  • 11
  • Thank you very much !!!!!!!!!!!!!!! It worked ! You've been a great help ! Gracias ! – Juri14 May 21 '14 at 02:56
  • Hi !! Do you know how to transfer data from textbox to the header of dgvcheckbox? Sorry for disturbing you once again . I hope you can help us with this . Thank You ! :)) – Juri14 May 21 '14 at 08:13
  • Not enough reputation left =D – GoroundoVipa May 21 '14 at 08:18
  • what do you mean by that? – Juri14 May 21 '14 at 08:21
  • It's like i haven't answer your first question because you didn't recognize it as an answer to your question. – GoroundoVipa May 22 '14 at 01:15
  • Thanks, if you have a problem don't shy to ask, thanks again... =D – GoroundoVipa May 22 '14 at 05:31
  • Actually we do have a problem, our problem is that we do not know how to transfer the value inputted in the textbox to the dgvcheckbox header . . – Juri14 May 22 '14 at 06:21
  • please help us again . .thank you very much :). im sorry for disturbing you again and again. . – Juri14 May 22 '14 at 06:21
  • http://stackoverflow.com/questions/23773304/how-can-we-transfer-the-value-of-a-textboxes-into-the-header-of-a-dvgcheckboxes . . here's the link thank you very much again – Juri14 May 22 '14 at 06:27
  • we have another problem . this the link : http://stackoverflow.com/questions/23863550/how-to-save-a-check-and-unchecked-checkboxes-from-datagridview-to-the-database-u . I hope someone can help us . AGAIN . :) – Juri14 May 26 '14 at 06:13
  • we have another problem . heres the link . : http://stackoverflow.com/questions/23879919/how-to-save-the-header-of-the-datagridview-in-database-using-vb-net . Can someone help us ??? Thank you . :)) . :D – Juri14 May 27 '14 at 05:31
0

I Think this is what you want...

enter image description here

This Code Actually Check every Cell that contains Checkbox Or 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
GoroundoVipa
  • 249
  • 3
  • 11
0

enter image description here

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

Leave the Attendance Column Blank cause the Total will be insert there...

Wew, I Think it solves your Problem =D

GoroundoVipa
  • 249
  • 3
  • 11
  • Thank You ! It worked . :) . Our only problem is how to count the unchecked checkboxes . Can you help us ? :) . Thank you once again . – Juri14 May 21 '14 at 00:53
  • :| I Already answered the first question but theres another follow up question hmmm... anyway let see, – GoroundoVipa May 21 '14 at 01:10
  • I'm sorry for disturbing you , But please help us because we're having a little trouble in solving this problem . We're just new in using vb.net and we're just a student . Thank you very much for helping us. – Juri14 May 21 '14 at 01:27
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

Okay Here it is all done...

GoroundoVipa
  • 249
  • 3
  • 11
  • Thank you . But something went wrong , once we click the button for calculating the unchecked checkboxes, 13 appeared in our cell instead of 10 only . Can you tell us what's wrong ? – Juri14 May 21 '14 at 01:53
  • I Can't visualize your DataGridView, Can you post some picture so i can construct the code. – GoroundoVipa May 21 '14 at 02:19
  • We can't post a picture. – Juri14 May 21 '14 at 02:26
  • Can you tell us how can we change the column count that appeared in our cell ? – Juri14 May 21 '14 at 02:28
  • I bit confuse about your datagridview first 5 is DGVTextBox and (Eleven DGVCheckBox ?) which means that you have a total of 5+11 = 16 Columns but you want to display the present in 11 and absent in 12 hmmm.... can you be more specific – GoroundoVipa May 21 '14 at 02:29
  • We just have eleven DataGridViewCheckBoxes but what appeared in our cell for the absents is fourteen. – Juri14 May 21 '14 at 02:29
  • Sorry . Our first five Column is DGVTextbox followed by 11 DGVCheckboxes . Then folowed once again by 2 DGVTextbox . 5 + 11 + 2 = 18 . We have 18 Columns and we want to display the present in the 17th and absent on the 18th . – Juri14 May 21 '14 at 02:32