G
Guest
I'm trying to write a procedure that sums the values of a column in a
datagridview. If a row is empty (has no value entered) the procedure
crashes. I've added code to check to see if the column for the row is blank,
this error apears:
Conversion from type 'DBNull' to type 'Integer' is not valid.
The code that I've written is: (the variables are defined)
Do Until dgvTblService.CurrentCell.RowIndex = varRowCount
varCol = dgvTblService.CurrentCell.ColumnIndex
varRow = dgvTblService.CurrentCell.RowIndex
If IsDBNull(Me.dgvTblService.CurrentRow.Cells(5)) Then
Me.dgvTblService.CurrentRow.Cells(5).Value =
Convert.ToDouble(0)
varSumHours +=
CInt(Me.dgvTblService.CurrentRow.Cells(6).Value)
Me.dgvTblService.CurrentCell = Me.dgvTblService(varCol,
varRow + 1)
Else
varSumHours +=
CInt(Me.dgvTblService.CurrentRow.Cells(6).Value)
Me.dgvTblService.CurrentCell = Me.dgvTblService(varCol,
varRow + 1)
End If
Loop
Any suggestions on what I'm doing wrong?
datagridview. If a row is empty (has no value entered) the procedure
crashes. I've added code to check to see if the column for the row is blank,
this error apears:
Conversion from type 'DBNull' to type 'Integer' is not valid.
The code that I've written is: (the variables are defined)
Do Until dgvTblService.CurrentCell.RowIndex = varRowCount
varCol = dgvTblService.CurrentCell.ColumnIndex
varRow = dgvTblService.CurrentCell.RowIndex
If IsDBNull(Me.dgvTblService.CurrentRow.Cells(5)) Then
Me.dgvTblService.CurrentRow.Cells(5).Value =
Convert.ToDouble(0)
varSumHours +=
CInt(Me.dgvTblService.CurrentRow.Cells(6).Value)
Me.dgvTblService.CurrentCell = Me.dgvTblService(varCol,
varRow + 1)
Else
varSumHours +=
CInt(Me.dgvTblService.CurrentRow.Cells(6).Value)
Me.dgvTblService.CurrentCell = Me.dgvTblService(varCol,
varRow + 1)
End If
Loop
Any suggestions on what I'm doing wrong?