RE: Deleting List Items

new topic     » goto parent     » topic index » view thread      » older message » newer message

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01C239C4.EFDC9860
 charset=iso-8859-1

Hi Robert,
> 
> I am looking for help with list views, particularly with 
> deleting items.  My 
> list are small (1-10 items)
> 
> Here is my original code:
> 
> for x = 1 to getCount(LV) do
>    VOID = deleteItem(LV, x)
> end for
>
> This works most of the time, 

I guess you are trying to delete all the items. This method will not work.
Here's why...

Let's say you have a list with 4 item in it. Thus the code is equivalent to:

   for x = 1 to 4 do:
      VOID = deleteItem(LV, x)
   end for

and this is equivalent to:

   VOID = deleteItem(LV, 1)
   VOID = deleteItem(LV, 2)
   VOID = deleteItem(LV, 3)
   VOID = deleteItem(LV, 4)

Now the parameter passed to deleteItem is the Row Number you wish to delete.
So after the first deleteItem() here the list will contain three rows. After
the second deleteItem() it will contain two rows. The third deleteItem() is
then going to try to delete Row #3 in a list that now only contains two
rows. Thus it fails to delete it.

There are four ways (at least) to delete all rows. The easiest is :

  eraseItems(LV)

The next easiest is :

  deleteItem(LV, -1)

If you need to do a loop, then either of these will work:

   for x = 1 to getCount(LV) do
       deleteItem(LV, 1) -- Always delete the top row.
   end for

or :

   for x = getCount(LV) to 1 by -1 do
       deleteItem(LV, x) -- Always delete the current bottom row.
   end for


>so I have implemented an addition...
> 
> while getCount(LV) > 0 do
>    for x = 1 to getCount(LV) do
>       VOID = deleteItem(LV, x)
>    end for
> end while
> 
> This seems to be better, but sometimes send the program into 
> a seemingly 
> infinite loop that it can not break free from.  

I don't understand why this doesn't work. I'll investigate a bit further. It
is a slow way to do it though.

-------------
cheers,
Derek.

==================================================================
De informatie opgenomen in dit bericht kan vertrouwelijk zijn en 
is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht 
onterecht ontvangt wordt u verzocht de inhoud niet te gebruiken en 
de afzender direct te informeren door het bericht te retourneren. 
==================================================================
The information contained in this message may be confidential 
and is intended to be exclusively for the addressee. Should you 
receive this message unintentionally, please do not use the contents 
herein and notify the sender immediately by return e-mail.


==================================================================

------_=_NextPart_000_01C239C4.EFDC9860
Content-Type: application/ms-tnef

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu