|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sum column of a DataGridVuewdatagridview. 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? -- Tony Tony,
Have a look at the datacolumn.compute statement, much easier in my idea http://msdn2.microsoft.com/en-us/library/system.data.datatable.compute.aspx I hope this helps, Cor Show quoteHide quote "Tony A." <To***@discussions.microsoft.com> schreef in bericht news:C68716F3-608A-4928-AA77-3DFD451ECE0A@microsoft.com... > 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? > -- > Tony It seems like you do the check on column 5 but sum column 6.
//Christer Show quoteHide quote "Tony A." <To***@discussions.microsoft.com> wrote in message news:C68716F3-608A-4928-AA77-3DFD451ECE0A@microsoft.com... > 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? > -- > Tony
Can't override CultureInfo.ToString
Mixed types in multidimensional arrays Re: ActiveX raise event - attn Walter Wang More than one method is found with VB but not with C# Multiple Component Classes Messages Did Mabry Software Tank! GET SUBNET LOCATION IN VB.NET OT-develing on several machines How to read XML from a string variable?? |
|||||||||||||||||||||||