cancel
Showing results for 
Search instead for 
Did you mean: 

how to delete datawindow row by loop?

Former Member
0 Kudos

I try to go through datawndow rows by for loop and delete those rows I found with condition.  Something like:

For i = 1 to dw_1.RowCount()

....

  if expression then 

    dw_1.DeleteRow(i)

  end if

Next

Looks like not working properly. if DeleteRow dynamically change RowCount()? how to resolve this problem?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI Kent;

  Suggestion: Try it in reverse ....

Long     ll_max

ll_max     =     dw_1.RowCount()

For i = ll_max to 1 STEP  -1

....

  if expression then 

    dw_1.DeleteRow(i)

  end if

Next

HTH

Regards ... Chris

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Kent,

You could apply a filter with you expression, then move rows to delete buffer and remove the filter:

dw_1.SetFilter ( expression )

dw_1.Filter()

dw_1,RowsMove ( 1, dw_1.RowCount () , Primary! , dw_1, 1, Delete! )

dw_1.SetFilter ('')

dw_1.Filter()

dw_1.Sort()

Just a thought

Lars

Former Member
0 Kudos

Good idea. Thanks.

Former Member
0 Kudos

If you must go from row 1 to RowCount(), then try this:

long ll_Row

ll_Row = 1

DO WHILE ll_Row <= dw_1.RowCount()

....

     IF expression THEN

          dw_1.DeleteRow(ll_Row)

     ELSE

          ll_Row++

     END IF

LOOP

HTH,

Manuel Marte

arnd_schmidt
Active Contributor
0 Kudos

To iterate from the last to the first row will do the trick:

long i

For i = dw_1.RowCount() To 1 Step -1

   ...

   If ( expression ) Then

      dw_1.DeleteRow ( i )

   End If

Next

hth

Arnd

Former Member
0 Kudos

If you don't need to delete the records in a specific order, try this:

ll_Row = dw_1.RowCount()

FOR i = ll_Row TO 1 STEP -1

....

  IF expression THEN

    dw_1.DeleteRow(i)

  END IF

NEXT

HTH,

Manuel Marte