Hi guys,
I have a BO filtered with records that needs to be deleted from the database, I am trying to use BO.GetEnumerable() to go trough each record and delete it, but of course the once it is deleted, it is removed from the currentview and mess the CurrentRowIndex, here is the code I tried:
Me.BizTransactionItemsStock1.Filter = "Flag_DeletedRecord = True"
For Each StockBO As bizTransactionItemsStock In Me.BizTransactionItemsStock1.GetEnumerable()
StockBO.DeleteCurrentRow(True)
Next
Then I simply decided to use another For..EndFor so the CurrentRowIndex will have no effect like this:
Me.BizTransactionItemsStock1.Filter = "Flag_DeletedRecord = True"
Dim lnReccount As Integer = Me.BizTransactionItemsStock1.Count
If lnReccount > 0 Then
For i As Integer = 1 To lnReccount
Me.BizTransactionItemsStock1.DeleteCurrentRow(True)
Next
End If
This code is working for me, but I want to make sure there is not better way to handle this? of course, after this, a BO.Save() will actually delete the records from the database.
Thanks!
P.S.
To all developers, be aware of the BO.Filter and BO.Sort effects which will immediately remove any record which does to comply with the Filter and for the Sort, it may mess your CurrentRowIndex as well while trying to enumerate the BO. These are very powerful features
, but also very tricky
Edhy Rijo