StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Deleting the first item in a ListExpand / Collapse
Author
Message
Posted 12/07/2006 4:33:00 PM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 06/19/2008 11:16:33 AM
Posts: 73, Visits: 12,471
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
Post #5104
Posted 12/07/2006 7:27:08 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 4:58:13 AM
Posts: 4,379, Visits: 4,421
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.

Post #5107
Posted 12/07/2006 9:39:51 PM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 06/19/2008 11:16:33 AM
Posts: 73, Visits: 12,471
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

Post #5113
Posted 12/07/2006 9:44:46 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 4:58:13 AM
Posts: 4,379, Visits: 4,421
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
Post #5114
Posted 12/07/2006 9:50:47 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 4:58:13 AM
Posts: 4,379, Visits: 4,421
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.
Post #5115
Posted 12/08/2006 8:26:25 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 06/19/2008 11:16:33 AM
Posts: 73, Visits: 12,471
Ah ... those two pieces of information are nice to know.  Thanks for your time and attention my friend.

CT

Post #5125
Posted 12/08/2006 9:00:50 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 4:58:13 AM
Posts: 4,379, Visits: 4,421
No problem
Post #5127
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 3:57am

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.078. 11 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.