What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [?] Clearing LstView Controls

Pages: (2): « First [ 1 ] 2 » Last »
[?] Clearing LstView Controls
Author: Message:
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
O.P. [?] Clearing LstView Controls
I have trouble with this before, but for some reason this doesn't seem to clear the whole list, it always seems to leave the last item if there are more than 2-3 items in the list... Any idea why? It looks Ok to me and I've tried looping it more times, but it doesn't work

code:
for(var i=0; i<=PlusWnd.LstView_GetCount("ListView");i++){
    PlusWnd.LstView_RemoveItem("ListView", 0);
}

<Eljay> "Problems encountered: shit blew up" :zippy:
10-03-2007 02:07 PM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: [?] Clearing LstView Controls
Try this instead! ;)
code:
//ListView_DeleteAll - Deletes all items
//Parameters: hWnd = control handle
function ListView_DeleteAll(hWnd) {
   var LVM_FIRST = 0x1000;
   var LVM_DELETEALLITEMS = (LVM_FIRST + 9);

   return new Boolean(Interop.Call("user32", "SendMessageW", hWnd, LVM_DELETEALLITEMS, 0, 0));
}

//Example
ListView_DeleteAll(PlusWnd.GetControlHandle("ListView"));

This post was edited on 10-03-2007 at 06:19 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
10-03-2007 02:32 PM
Profile E-Mail PM Web Find Quote Report
Volv
Skinning Contest Winner
*****

Avatar

Posts: 1233
Reputation: 31
34 / Male / Flag
Joined: Oct 2004
RE: [?] Clearing LstView Controls
Or you could use a while(PlusWnd.LstView_GetCount("ListView")) loop which would probably work as well. But I suppose Mattike's method is better :p

EDIT: Also your current method is looping 1 more time than is necessary as LstView_GetCount gives you the number of items in the listview, not the highest index - have you checked your Script Debugging Window?

This post was edited on 10-03-2007 at 02:44 PM by Volv.
10-03-2007 02:40 PM
Profile PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
O.P. RE: [?] Clearing LstView Controls
quote:
Originally posted by Mattike
Try this instead!

That causes an error and so doesn't work

quote:
Originally posted by Volv
Or you could use a while(PlusWnd.LstView_GetCount("ListView")) loop

That just isn't removing any items ^o)

quote:
Originally posted by Volv
EDIT: Also your current method is looping 1 more time than is necessary - have you checked your Script Debugging Window?

I was tracing the LstView_Count property and it never got down to zero... it would just keep looping at 1



EDIT: fixed a spelling mistake in Mattike's.... Now it does the same thing as Volv's... Lol.

This post was edited on 10-03-2007 at 02:59 PM by Spunky.
<Eljay> "Problems encountered: shit blew up" :zippy:
10-03-2007 02:49 PM
Profile PM Find Quote Report
Volv
Skinning Contest Winner
*****

Avatar

Posts: 1233
Reputation: 31
34 / Male / Flag
Joined: Oct 2004
RE: [?] Clearing LstView Controls
I believe your original problem is related to the fact that PlusWnd.LstView_GetCount("ListView") is not constant (it decreases each time you remove an item) and as such your 'i' isn't going through all the necessary loops.
It works for 1 item because it loops through '0'.
It works for 2 items because it loops through '0', '1'.
It does not work for 3 items because it loops through '0', '1'.
It does not work for 4 items because it loops through '0', '1', '2'.
etc.

EDIT: I don't see why my while() loops wouldn't work though :P (I haven't tried it though)

This post was edited on 10-03-2007 at 03:03 PM by Volv.
10-03-2007 02:58 PM
Profile PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
O.P. RE: [?] Clearing LstView Controls
I did manage to do it once before...

@Volv: The loop always removes index 0 so it should always remove the top one in the list... there should ALWAYS be a top item in the list

I think we should have a function to clear LstViews and Combos in the next version ;)
<Eljay> "Problems encountered: shit blew up" :zippy:
10-03-2007 03:00 PM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1621
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: [?] Clearing LstView Controls
It should be
code:
while(PlusWnd.LstView_GetCount("ListView") != 0)
This will give a boolean expression like the while statement wants ;)

This method I have found works well, I have used it before with Message Customizer! Live when I did the groups to clear out the list views. However, seeing as though Mattike uses windows API it might be quicker and nicer to use that (especially on larger lists).
[Image: markee.png]
10-03-2007 03:03 PM
Profile PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
O.P. RE: [?] Clearing LstView Controls
quote:
Originally posted by markee
code:
while(PlusWnd.LstView_GetCount("ListView") != 0)


I did try that too... I might give it another go though
<Eljay> "Problems encountered: shit blew up" :zippy:
10-03-2007 03:04 PM
Profile PM Find Quote Report
Volv
Skinning Contest Winner
*****

Avatar

Posts: 1233
Reputation: 31
34 / Male / Flag
Joined: Oct 2004
RE: RE: [?] Clearing LstView Controls
quote:
Originally posted by markee
It should be
code:
while(PlusWnd.LstView_GetCount("ListView") != 0)
This will give a boolean expression like the while statement wants ;)

code:
while(PlusWnd.LstView_GetCount("ListView") > 0)
Hmph, > owns != :P



quote:
Originally posted by SpunkyLoveMuff
I did try that too... I might give it another go though
You should have something like this:
code:
while(PlusWnd.LstView_GetCount("ListView") > 0){
    PlusWnd.LstView_RemoveItem("ListView", 0);
}

This post was edited on 10-03-2007 at 03:10 PM by Volv.
10-03-2007 03:07 PM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1621
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: [?] Clearing LstView Controls
It doesn't matter if you use > or != in this situation because there is no time when it won't return a number equal to or greater than zero.  This is because the only error is if the plus window does not exist or the control ID doesn't exist.  As far as I can tell wouldn't it be quickest to do !== rather than the other 2?
[Image: markee.png]
10-03-2007 03:14 PM
Profile PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On