Deleting the first item in a List


Author
Message
Charles Thomas Blankenship...
Charles Thomas Blankenship
Advanced StrataFrame User (708 reputation)Advanced StrataFrame User (708 reputation)Advanced StrataFrame User (708 reputation)Advanced StrataFrame User (708 reputation)Advanced StrataFrame User (708 reputation)Advanced StrataFrame User (708 reputation)Advanced StrataFrame User (708 reputation)Advanced StrataFrame User (708 reputation)Advanced StrataFrame User (708 reputation)
Group: Awaiting Activation
Posts: 172, Visits: 12K
Everytime I delete the first item in my list I get the following error:





The CurrentRow could not be evaluated because the CurrentRowIndex is out of range. Business object record count: 7. CurrentRowIndex: -1.



A closer evaluation of the code shows the following issue ... when the list is at the first item ... the _CurrentRowIndex is already at 0 ... the -= 1 changes this to a negative one which throws the error above. Should I put a check in there to see if the _CurrentrowIndex is already 0 before decrementing?





If loCurrentPk.Equals(PKValue) Then

'-- Remove the current row and navigate to the next row

loRow = Me.CurrentRow

loRow.Delete()

loRow.AcceptChanges()



'-- Decrement the index and navigate

Me._CurrentRowIndex -= 1

Me.Navigate(BusinessNavigationDirection.Next)

Else

'-- Find the row to delete

If Me.SeekToPrimaryKey(PKValue) Then

'-- Remove the row

loRow = Me.CurrentRow

loRow.Delete()

loRow.AcceptChanges()



'-- Move back to the original row

Me.SeekToPrimaryKey(loCurrentPk)

End If

End If







This has been a long hard non-billable day my friends.



Thanks,



CTBlankenship

Charles T. Blankenship
Senior Consultant
Novant Consulting, Inc.
704.975.7152
http://www.novantconsulting.com
Reply
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
You are not going to want to delete through the CurrentRow...this may potentitally wreak havoc on a number of different levels.  First of all you should really use the following command:

MyBO.DeleteCurrentRow(True)

The above command will only mark the row as deleted (the True) and not go back to the server, obviously False will go back to the server.  Second, if you don't want to commit the changes, then you can call the following command:

MyBO.CurrentDataTable.AcceptChanges()

This wasy you are staying within the logic of the BO.  Even if you want to call the delete on the data table directly would be safer than passing of the row reference and the smoking it:

MyBO.CurrentDataTable.Rows(MyBO.CurrentRowIndex).Delete()

Any of these are going to be much safer.  I recommend the first option as it remains within the BO logic.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search