Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrids/Datasets/Datatables

Status
Not open for further replies.

WMthompson

IS-IT--Management
Aug 10, 2005
3
0
0
US
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
 
Try your code using the MouseUp event.

I hope this helps.

Ron

Ron Repp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top