StrataFrame Forum

Empty table and BO CurrentRowIndex exception

http://forum.strataframe.net/Topic11368.aspx

By Doug Birtell - 9/6/2007

All, (anybody)

When I run a SF maintenance form that uses a BO that references an empty table, I get the following exception.

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

If I manually add a row to the table, then the app works fine.  Is there some way to check the CurrentRowIndex within the BO to keep the application from choking?  The table that this SF form maintains will always be empty to start with.

Thanks!

By Greg McGuffey - 9/6/2007

Well, the only way I know of that you'd get this exception is if you are referencing a field within the BO either in your form or in a fill method. I've run into this with custom properties that look up something based on the value of a field in the current row. I.e. I have a FK (in ID) to another table and I use a custom property to use this ID to look up the name of the item. I have to have code that checks on the CurrentRowIndex to make sure there is a current row or I get this exception.



Some more details (like the stack trace) would probably narrow this down really quick.
By Doug Birtell - 9/6/2007

Greg,

Thanks for the clue.  It looks like the navigated event on the form was getting called first thing, and it was using a pk field form the primary business object (which is empty) to fill another BO.  I added a check to make sure that the cuurrent row index was > 0 before loading the other BO's and it all works fine now.

Regards,

Doug

By Trent L. Taylor - 9/6/2007

You got it.  Smile  The only time this error will occur is when a strong-type field property, custom or otherwise, is referenced and there are no records visible within the CurrentView (no records, filtered out, etc).  So as you discovered, if you test on the Count you will be able to safely reference the field properties.
By Greg McGuffey - 9/7/2007

Yep, this one's bitten me a bunch of time! Glad you got it figured out!