﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Best practice to Enumerate BO to delete current row...</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Mon, 18 May 2026 03:16:34 GMT</lastBuildDate><ttl>20</ttl><item><title>Best practice to Enumerate BO to delete current row...</title><link>http://forum.strataframe.net/FindPost23627.aspx</link><description>Hi guys,&lt;br&gt;
&lt;br&gt;
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:&lt;br&gt;
[codesnippet]&lt;br&gt;
        Me.BizTransactionItemsStock1.Filter = "Flag_DeletedRecord = True"&lt;br&gt;
        For Each StockBO As bizTransactionItemsStock In Me.BizTransactionItemsStock1.GetEnumerable()&lt;br&gt;
            StockBO.DeleteCurrentRow(True)&lt;br&gt;
        Next&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
Then I simply decided to use another For..EndFor so the CurrentRowIndex will have no effect like this:&lt;br&gt;
[codesnippet]&lt;br&gt;
   Me.BizTransactionItemsStock1.Filter = "Flag_DeletedRecord = True"&lt;br&gt;
        Dim lnReccount As Integer = Me.BizTransactionItemsStock1.Count&lt;br&gt;
        If lnReccount &gt; 0 Then&lt;br&gt;
            For i As Integer = 1 To lnReccount&lt;br&gt;
                Me.BizTransactionItemsStock1.DeleteCurrentRow(True)&lt;br&gt;
            Next&lt;br&gt;
        End If&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Thanks!&lt;br&gt;
&lt;br&gt;
P.S.&lt;br&gt;
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 :D</description><pubDate>Tue, 13 Oct 2009 13:41:44 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Best practice to Enumerate BO to delete current row...</title><link>http://forum.strataframe.net/FindPost24917.aspx</link><description>Hi Les,&lt;/P&gt;&lt;P&gt;glad to see you here!</description><pubDate>Tue, 13 Oct 2009 13:41:44 GMT</pubDate><dc:creator>Michel Levy</dc:creator></item><item><title>RE: Best practice to Enumerate BO to delete current row...</title><link>http://forum.strataframe.net/FindPost24903.aspx</link><description>Hi Les,&lt;br&gt;
&lt;br&gt;
Glad to see you in the StrataFrame community, it will be very positive for all.&lt;br&gt;
&lt;br&gt;
About your sample approach, it is interesting, thanks, I will test it with my project.</description><pubDate>Tue, 13 Oct 2009 08:48:11 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Best practice to Enumerate BO to delete current row...</title><link>http://forum.strataframe.net/FindPost24902.aspx</link><description>Les !!&lt;br&gt;
&lt;br&gt;
How nice to see [b]you[/b] here after all these years.  I believe the last time I saw you I was manning the F1 booth near yours at ... Ft. Lauderdale?  Palm Springs?  I remember Ceil was running around taking pictures.  ( man I miss her) &lt;br&gt;
&lt;br&gt;
Anyway, welcome to Strataframe.  I think you are going to love it and I know your contribution to this community will be very welcome.  If you've not yet had the opportunity to meet the Taylor family I know you will enjoy each other.  &lt;br&gt;
&lt;br&gt;
There is a lot of real-world pragmatism and appreciation of "Microsoft realities" built into this framework and I've found it invaluable in getting very productive in .NET.&lt;br&gt;
&lt;br&gt;
Hope we see a lot of you here.&lt;br&gt;
&lt;br&gt;
( for the benefit of non-Fox lurkers who may not know him - Les is one of the best known authors, teachers and speakers in the Foxpro world as  well as being one of the most colorful and interesting characters in anybody's world :D )</description><pubDate>Tue, 13 Oct 2009 07:38:27 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Best practice to Enumerate BO to delete current row...</title><link>http://forum.strataframe.net/FindPost24900.aspx</link><description>Hi Edhy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I used this with a little test database containing a Flag_DeletedRecord column, and it worked fine:&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;{BO1.Filter = "Flag_DeletedRecord = True";&lt;BR&gt;&amp;nbsp;if (BO1.Count &amp;gt; 0) { do { BO1.DeleteCurrentRow(); } while (BO1.Count &amp;gt; 0); }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;BO1.Save(); BO1.Filter = "";}&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp; I hope this relates to what you're doing. Good seeing your name again after all these years...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;Les&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Tue, 13 Oct 2009 06:15:25 GMT</pubDate><dc:creator>Les Pinter</dc:creator></item><item><title>RE: Best practice to Enumerate BO to delete current row...</title><link>http://forum.strataframe.net/FindPost24897.aspx</link><description>[quote][b]Paul Chase (06/19/2009)[/b][hr]Edhy, if you loop through backwards and delete then current index won't get out of whack.[/quote]&lt;br&gt;
&lt;br&gt;
Hi Paul,&lt;br&gt;
&lt;br&gt;
Just to let you know that today I came across a situation where your suggestion fitted perfectly.  &lt;br&gt;
&lt;br&gt;
Thanks again for sharing.</description><pubDate>Mon, 12 Oct 2009 22:35:30 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Best practice to Enumerate BO to delete current row...</title><link>http://forum.strataframe.net/FindPost23629.aspx</link><description>Hi Paul,&lt;br&gt;
&lt;br&gt;
Thanks, I did not even consider that option and sure it does make sense.  I will test it.</description><pubDate>Fri, 19 Jun 2009 14:22:29 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Best practice to Enumerate BO to delete current row...</title><link>http://forum.strataframe.net/FindPost23628.aspx</link><description>Edhy,&lt;/P&gt;&lt;P&gt;If you loop through backwards&amp;nbsp;and delete then current index won't get out of whack.&lt;/P&gt;&lt;P&gt;&amp;nbsp;[codesnippet]&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;For&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; i &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Integer&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;MyBO&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.Count - 1 &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;To&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; 0 &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Step&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; -1&lt;/P&gt;&lt;P&gt;&amp;nbsp;If MyBO.somefield = Something Then&lt;/P&gt;&lt;P&gt;Delete&lt;/P&gt;&lt;P&gt;Endif&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Next&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;[/codesnippet]</description><pubDate>Fri, 19 Jun 2009 14:08:42 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item></channel></rss>