Deleting the first item in a List


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
No problem Smile
Charles Thomas Blankenship...
Charles Thomas Blankenship
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Awaiting Activation
Posts: 172, Visits: 12K
Ah ... those two pieces of information are nice to know.  Thanks for your time and attention my friend.

CT

Charles T. Blankenship
Senior Consultant
Novant Consulting, Inc.
704.975.7152
http://www.novantconsulting.com

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
After looking at the code and running a test, the code in the DeleteByPrimaryKey is actually correct.  The Navigate accounts for a negative row index.  There is something else going on in your environment that could be causing the problem.  Just so you know, you don't even need any records in the BO in order to delete a record from the server.  If you are wanting to delete a record from the server that is already in your BO, the use the DeleteCurrentRow method...you will have fewer issues with other bindings and delegates that may be in the formula.
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Oh....I will look into this....you will get the results you are looking for calling the following method:

MyBO.DeleteCurrentRow(False)

But be sure to navigate to the proper row before smoking it:

If MyBO.SeekToPrimaryKey(MyPrimaryKey) Then
    MyBO.DeleteCurrentRow(False)
End If

Charles Thomas Blankenship...
Charles Thomas Blankenship
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Awaiting Activation
Posts: 172, Visits: 12K
Hey Buddy:



I'm calling this method ...



Private Function DeleteByPrimaryKey(ByVal PKValue As PrimaryKeyValue) As Integer



which has this code in it



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



Notice that the value in Me._CurrentRowIndex is not tested for 0 before a decrement occurs ... in my case this causes the the _CurrentRowIndex to contain a -1 which throws the aforementioned error. Sorry I mislead you by not posting the whole piece of the pie.



Thanks,



CT




Charles T. Blankenship
Senior Consultant
Novant Consulting, Inc.
704.975.7152
http://www.novantconsulting.com
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.

Charles Thomas Blankenship...
Charles Thomas Blankenship
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 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
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