PDA

View Full Version : listview selecting all items slowdown.


PEN
04-17-2009, 03:41 PM
Here is the function in question..

fn selectAll lv state:true=
(
st=timeStamp()
for i = 0 to lv.items.count-1 do
(
lv.items.item[i].selected=state
)
ed=timeStamp()
format "selectAll: % Sec\n" ((ed-st)/1000)
setFocus lv
),

This is from my reset xform tool available on my site. For some reason it takes 98 seconds to select 418 items in the list.

Can any one tell me if there is a faster way or what I might be doing wrong?

DaveWortley
04-17-2009, 03:52 PM
Can you re-write it to use....

for o in ... do

rather than for i = 1 to .... do

Isn't it much quicker to use the first in certain instances?

PEN
04-17-2009, 03:58 PM
I don't think it is the loop that is causing the problem. It loops through instantly if it isn't doing anything or just printing out text.

PEN
04-17-2009, 04:01 PM
I just tested collecting all the items into an array and that happens in .5 of a second. It is when I try and select them. Is it because the selection is happening one item at a time and it is trying to redraw constantly?

marktsang
04-17-2009, 04:06 PM
try beginUpdate() ... endUpdate()

probably because its constantly redrawing as you said

PEN
04-17-2009, 04:13 PM
Good try Mark, but it didn't help.

marktsang
04-17-2009, 04:14 PM
how about .SuspendLayout()? in conjunction with beginUpdate endUpdate?

marktsang
04-17-2009, 04:18 PM
:)
time is scarce for those web thingys

want to post an example that has the problem so i can have a stab at it?

PEN
04-17-2009, 04:19 PM
Still nothing.

Love the new web site Mark, so simple and straight to the point;)

marktsang
04-17-2009, 04:25 PM
wow,
i think i time traveled there for a moment?

LoneRobot
04-17-2009, 04:33 PM
Hey Paul,

i think it's to do with the handler you are using - SelectedIndexChanged, as it is calling that each time the function loops, causing the slowdown. Could you change to your mouseup handler (for the individual mouse clicks)

on scaleListLv mouseUp senderArg arg do
(
PEN_resetXform2.selectObjectsInList scaleListLv
)

and remove the SelectedIndexChanged one? that way you could just loop the objects into an array as you set the listview selected state, thus not interfering with any events tied to the selection of a node -


fn selectAll lv state:true=
(
local sel = #()
st=timeStamp()

for i = 0 to lv.items.count-1 do
(
lv.items.item[i].selected=state
append sel lv.SelectedItems.item[i].tag.value
)

select sel
setFocus lv
ed=timeStamp()
format "selectAll: % Sec\n" ((ed-st)/1000)
)

this method selects the items quickly, at any rate.

PEN
04-17-2009, 06:11 PM
Doh!!, I should have know that as I have had similar issues in the past. Thanks a million. I'm better that will do it since each time the selection changes it goes through it again.

PEN
04-17-2009, 06:12 PM
Just thought I was using it so you can just key up and down the list and see what objects get selected. I'll have to rework that some how.

PEN
04-17-2009, 06:51 PM
Yup, that was it. Just need to sort out how to work it so when the selection changes from keyboard input that it doesn't spam it. I think I will set a flag for that.

CGTalk Moderation
04-17-2009, 06:51 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.