1. RE: Deleting List Items

Robert, 

If you're looking to remove all items from the list then use 
eraseItems().

HTH,

Jonas
rswiston at hotmail.com wrote:
> Sorry if this message reaches everyone twice... problems with Topica 
> (yeah, 
> like there's a surprise!) have prevented my first one from being sent 
> (or at 
> least so I think?!)
> 
> 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, 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.  It appears that win32lib 
> 
> does not always delete an item from a list view even though the program 
> is 
> coded to do exactly that.
> 
> Is this a bug?  Can someone explain what I might be missing here?  This 
> also 
> happens in Lists, and Combo Boxes...?
> 
> -Robert
> 
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
> 
>

new topic     » topic index » view message » categorize

2. RE: Deleting List Items

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 message » categorize

3. RE: Deleting List Items

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_01C239C9.D8564F60
 charset=iso-8859-1

> This sometimes leaves a line or two in the list view... so 
> I've added this
> 
> while getCount(LV) > 0 do
>    for x = 1 to getCount(LV) do
>       VOID = deleteItem(LV, x)
>    end for
> end while
> 
> While this helps 90% of the time, there are occasions that 
> the computer 
> "sits and spins" seemingly involved in an infinite loop that 
> it cannot seem 
> to break out of.
> 
> Of course I have tried VOID = deleteItem(LV, -1) with no 
> greater success.

Now I think I know why. I suspect you are using an early version of
win32lib. This did ListViews differently than the current version.

In the old versions of win32lib, that parameter to deleteItem() was not a
Row number but an Item ID. It use to be that each item added to a listview
was given a unique ID, and to delete them, you need to pass the item's ID.
That has all changed - sort of. Items are still given unique ids, but most
listview routines now work with row numbers and not ids. 

The above code might not have worked because the item's id was not always
the same as its row number. So if you thought you were deleting the n'th
item in the list, you might have been actually deleting an item in another
list altogether - or nothing at all.

The old versions also had a bug in which the deleteItem(LV, -1) didn't work.

You can get a newer version from ...

   http://www.users.bigpond.com/ddparnell/euphoria/euphoria.htm 

and hopefully, I can even upload an updated version this coming weekend.

----------
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_01C239C9.D8564F60
Content-Type: application/ms-tnef

new topic     » goto parent     » topic index » view message » categorize

4. RE: Deleting List Items

Thanks Derek and all who responded to my query yesterday...

eraseItems(LV) works just fine (why didn't I see that one before... boy I 
feel like a shmuck!)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu