Board index » delphi » Fastest way of clearing a ListView

Fastest way of clearing a ListView

I use a listview, it's great, but when working with 2500 lines it goes slow,
the real problem is when I change catalog, Delphi uses the same amount of
time clearing the listview at is is insering them, is it possible to do this
quicker?

 

Re:Fastest way of clearing a ListView


Quote
Thomas Nomeland L?vlie wrote:

> I use a listview, it's great, but when working with 2500 lines it goes slow,
> the real problem is when I change catalog, Delphi uses the same amount of
> time clearing the listview at is is insering them, is it possible to do this
> quicker?

A few things, first try using:

  Listview.Items.BeginUpdate
  try
    Items.Clear
    ...or...
    Items.add
  finally
    Listview.Items.EndUpdate;
  end;

Second, adding items to a listview takes time where as reusing items in
a listview takes much less time so if you can, try to avoid clearing the
entire listview if you know you are only going to fill it back up.
Reuse the items that are already there by simply changing exisitng
items/subitems.

--
-Steve
Delphi QA
(If you are responding to a post please response to the newsgroup
 otherwise, to email me remove "-nojunkmail-" from my address.)

Re:Fastest way of clearing a ListView


Quote
Thomas Nomeland L?vlie wrote:

> I use a listview, it's great, but when working with 2500 lines it goes slow,
> the real problem is when I change catalog, Delphi uses the same amount of
> time clearing the listview at is is insering them, is it possible to do this
> quicker?

...and one I forgot to mention which is check out the AllocBy property
on the listview.

--
-Steve
Delphi QA
(If you are responding to a post please response to the newsgroup
 otherwise, to email me remove "-nojunkmail-" from my address.)

Other Threads