WMthompson
IS-IT--Management
I have a form that contains a datagrid. I am trying to calculate members of other cells if certain conditions are true using the datagrid.currentcellchanged event. The code performs the calculations fine but gets into a loop that it is caused by the event itself. Anytime a cell changes, which it does on calculation, it triggers the event. Is there a way to manipulate the dataset or datatable so that the event does not get triggered, and, I can refresh the datagrid once the calculations are performed. Thanks, MT
Dim myCell As New DataGridCell
Dim MaxCount As Integer
Dim I As Integer
Dim MinCount As Integer
myCell = DataGrid1.CurrentCell
' Check for History Flag or not
If DataGrid1.Item(myCell.RowNumber, 17) = 0 Then
'Define Loop Variables
MaxCount = dsPSI.Tables(0).Rows.Count
MinCount = myCell.RowNumber
If myCell.ColumnNumber = 5 Or myCell.ColumnNumber = 6 Or myCell.ColumnNumber = 7 Or myCell.ColumnNumber = 8 Or myCell.ColumnNumber = 9 Or myCell.ColumnNumber = 10 Or myCell.ColumnNumber = 11 Or myCell.ColumnNumber = 12 Then
If Not txtCheck = cmbPSICAt.SelectedValue Then
If Not IsDBNull(DataGrid1.Item(myCell.RowNumber, 0)) Then
If DataGrid1.Item(myCell.RowNumber, 15) < 0 Then DataGrid1.Item(myCell.RowNumber, 15) = 0
For I = MinCount To MaxCount - 1
DataGrid1.Item(I, 13) = (DataGrid1.Item(I, 4) * DataGrid1.Item(I, 8) + DataGrid1.Item(I, 5) * DataGrid1.Item(I, 9) + DataGrid1.Item(I, 6) * DataGrid1.Item(I, 10) + DataGrid1.Item(I, 7) * DataGrid1.Item(I, 11))
DataGrid1.Item(I, 15) = DataGrid1.Item(I - 1, 15) + DataGrid1.Item(I, 13) - DataGrid1.Item(I, 14)
If DataGrid1.Item(I, 15) < 0 Then DataGrid1.Item(I, 15) = 0
Next I
End If
End If
End If
End If
Dim myCell As New DataGridCell
Dim MaxCount As Integer
Dim I As Integer
Dim MinCount As Integer
myCell = DataGrid1.CurrentCell
' Check for History Flag or not
If DataGrid1.Item(myCell.RowNumber, 17) = 0 Then
'Define Loop Variables
MaxCount = dsPSI.Tables(0).Rows.Count
MinCount = myCell.RowNumber
If myCell.ColumnNumber = 5 Or myCell.ColumnNumber = 6 Or myCell.ColumnNumber = 7 Or myCell.ColumnNumber = 8 Or myCell.ColumnNumber = 9 Or myCell.ColumnNumber = 10 Or myCell.ColumnNumber = 11 Or myCell.ColumnNumber = 12 Then
If Not txtCheck = cmbPSICAt.SelectedValue Then
If Not IsDBNull(DataGrid1.Item(myCell.RowNumber, 0)) Then
If DataGrid1.Item(myCell.RowNumber, 15) < 0 Then DataGrid1.Item(myCell.RowNumber, 15) = 0
For I = MinCount To MaxCount - 1
DataGrid1.Item(I, 13) = (DataGrid1.Item(I, 4) * DataGrid1.Item(I, 8) + DataGrid1.Item(I, 5) * DataGrid1.Item(I, 9) + DataGrid1.Item(I, 6) * DataGrid1.Item(I, 10) + DataGrid1.Item(I, 7) * DataGrid1.Item(I, 11))
DataGrid1.Item(I, 15) = DataGrid1.Item(I - 1, 15) + DataGrid1.Item(I, 13) - DataGrid1.Item(I, 14)
If DataGrid1.Item(I, 15) < 0 Then DataGrid1.Item(I, 15) = 0
Next I
End If
End If
End If
End If