PDA

View Full Version : Example: Using Send Message to Populate Listbox


Worm
01-18-2007, 01:27 PM
I've seen some posts here where it has been stated the Listbox gets slow when there are a lot of items. Here is a way to populate the Listbox using a function I wrote that uses SendMessage (User32.dll function) to add the items to the Listbox.

I tried populating a Listbox with ListBox.AddItem with 5000 items. I killed the task after 4 minutes. Using this function, it took 6 seconds to add the 5000 items :)

Enjoy!

Desmond
01-18-2007, 02:03 PM
It is also possible to add a wack of items quickly by first stopping the listbox from updating it's view until you're finished:


-- Stop listbox from updating
ListBox.SetUpdate("ListBox1", false);

-- Add 5000 items
min = 1; -- The number to start at
max = 5000; -- The number to stop at
for count=1, 5000 do
ListBox.AddItem("ListBox1", count, "");
end

-- Let the listbox update
ListBox.SetUpdate("ListBox1", true);

Worm
01-18-2007, 02:05 PM
That's faster yet!

Plus I just realized the function I posted doesn't work properly!
It adds the item to the listbox, but you can't select them.... yikes!

rhosk
01-18-2007, 04:37 PM
Uh, Worm, let's QA these things a little better, eh?

...kidding...

Worm
01-18-2007, 09:23 PM
Heee!

That's a definite. Although its very odd that the item shows in the listbox, yet won't select. Ya gotta give me that, right?

I'm grabbin' here man, help a brother out, eh.

Desmond
01-19-2007, 08:54 AM
'Tis odd ... But my way is still better! mua ha ha ha ha ha ha ha!!! :D

Worm
01-19-2007, 09:06 AM
yup it is.