Private Sub FillDataGrid()
Dim dtData As New DataTable()
'#### Columns ####
'make new columns
Dim DaysInMonth As Integer = DateTime.DaysInMonth(Now.Year, (cboMonth.SelectedIndex + 1))
'get employees for department and month
Dim dtEmployees As DataTable = GetEmployeeTable(cboDepartment.SelectedValue.ToString, R.Next(12, 25))
'get existing employee attendance for the current month
Dim dtAttendance As DataTable = GetEmployeeAttendance(dtEmployees, (cboMonth.SelectedIndex + 1))
'add employeeid column
dtData.Columns.Add("EmployeeID", Type.GetType("System.Int32"))
'add day columns to table
Dim dc As DataColumn
For ColCnt As Integer = 1 To DaysInMonth
dc = New DataColumn("Day" & ColCnt.ToString(), Type.GetType("System.Boolean"))
dc.AllowDBNull = False
dc.DefaultValue = False
dtData.Columns.Add(dc)
Next
dtData.AcceptChanges()
'#### Columns ####
'#### Fill Table Data ####
Dim drNew As DataRow
'Adds the employeeIds to the grid
For Each dr As DataRow In dtEmployees.Rows
drNew = dtData.NewRow()
drNew("EmployeeID") = DirectCast(dr("EmployeeID"), Int32)
Dim drAttend() As DataRow = dtAttendance.Select("EmployeeID = " & DirectCast(dr("EmployeeID"), Int32))
If drAttend.Length > 0 Then
'loop and add the employee attendance
For AttCnt As Integer = 0 To drAttend.Length - 1
drNew("Day" & DirectCast(drAttend(AttCnt)("AttendanceDate"), DateTime).Day.ToString()) = True
Next
End If
dtData.Rows.Add(drNew)
Next
dtData.AcceptChanges()
'#### Fill Table Data ####
'#### Fill Grid ####
dgvAttendance.DataSource = dtData
'#### Fill Grid ####
End Sub