Board index » delphi » Very slow while adding items in TListView

Very slow while adding items in TListView

  I've created a new component derived from TListView. I use it to
display read-only dataset populating columns and rows at runtime.

  After opening dataset I set AllocBy to the number of record and use
BeginUpdate and EndUpdate to prevent scrolling and than I create
columns. After I add new items using TListItems.Add.

  In 90 % of cases all work fine (very fast with about 300 items). But
sometimes it takes several seconds (about 20) to add the same numer of
items.

  Thanks for helps

Stefano Scriboni

 

Re:Very slow while adding items in TListView


Hi Stefano,

one reason could be that you have set the "SortType" property of the
ListView not to stNone. In this case the ListView add a new Item in a
sorted order, which is very time cosuming.

Alfons

Quote
Stefano Scriboni wrote:
>   I've created a new component derived from TListView. I use it to
> display read-only dataset populating columns and rows at runtime.

>   After opening dataset I set AllocBy to the number of record and use
> BeginUpdate and EndUpdate to prevent scrolling and than I create
> columns. After I add new items using TListItems.Add.

>   In 90 % of cases all work fine (very fast with about 300 items). But
> sometimes it takes several seconds (about 20) to add the same numer of
> items.

>   Thanks for helps

> Stefano Scriboni

Re:Very slow while adding items in TListView


Alfons Natter ha scritto:

Quote
> Hi Stefano,

> one reason could be that you have set the "SortType" property of the
> ListView not to stNone. In this case the ListView add a new Item in a
> sorted order, which is very time cosuming.

> Alfons

Thanks Alfons.

Finally I found the reason is that I set, in a TListView object,
columns.width = -1 (or -2) to dinamically adapt the width in respect to
contents of the column. This is a very time-consuming task while populating
the column.

Quote
> Stefano Scriboni wrote:

> >   I've created a new component derived from TListView. I use it to
> > display read-only dataset populating columns and rows at runtime.

> >   After opening dataset I set AllocBy to the number of record and use
> > BeginUpdate and EndUpdate to prevent scrolling and than I create
> > columns. After I add new items using TListItems.Add.

> >   In 90 % of cases all work fine (very fast with about 300 items). But
> > sometimes it takes several seconds (about 20) to add the same numer of
> > items.

> >   Thanks for helps

> > Stefano Scriboni

Other Threads