Re: listview

From: James Emerton (james.emerton_at_nospamthanksntlworld.com)
Date: 03/10/05

  • Next message: Jamie: "Re: listview"
    Date: Thu, 10 Mar 2005 18:38:00 GMT
    
    

    Jamie wrote:
    > James Emerton wrote:
    >
    >> Is there a way to load icons for a listview "on the fly" without using
    >> an imagelist? or else is there a way to add/delete items from an
    >> imagelist associated with a listview without the listview updating?
    >>
    >> Thanks
    >>
    >> James
    >>
    >> PS I have googled for an answer to this and though the question has
    >> been asked a couple of times I couldn't see an answer.
    >>
    >> PPS would like to avoid ownerdraw if possible
    >
    >
    > the imagelist has "replace" and "Add"
    > etc..
    >
    Jeremy / Jamie

    Thank you both for your reply.

    Hopefully I can clarify the what I am trying to achieve.

    I have a listview with several thousand lines. It is a virtual listview.
    That is I provide the data for the listview as "requested" by the
    listview through the ondata event.

    I am looking for a similar method of providing the icon.

    At the moment I have some code in the ondata event which replaces the
    imagelist(0) image with the appropriate icon and changes the imageindex
    for the item for which the ondata event was called to 0.

    Here is the relevant code

    procedure TFormmain.ListView1Data(Sender: TObject; Item: TListItem);
    var
             filenamestring :string;
             icon :ticon;
    begin
    ..snip...
             icon := ticon.Create;
    {filenamestring contains location of icon}
             if (fileexists(filenamestring)) then
                     icon.LoadFromFile(filenamestring)
             else
                    icon.Assign(formmain.defaulticon.Picture.icon);
            formmain.imagelistrealsmall.ReplaceIcon(0,icon);
            formmain.imagelistreallarge.ReplaceIcon(0,icon);
           icon.Destroy;
           item.ImageIndex := 0;
    ....snip.....
    end;

    The above works except that the listview starts to "flicker" constantly
    and cpu usage shoots up to 100%. I assume that this is because if you
    change an imagelist that is associated with a listview the listview
    automatically updates. Thus the ondata event is constantly re-calling
    itself every time the imagelist changes.

    Hence my original request for a way to:

    "add/delete items from an
    >> imagelist associated with a listview without the listview updating?"

    I have tried both methods suggested i.e "replace" and "loadicon" and
    both lead to the flickering.

    doublebffered=true does stop the flickering but slows the listview down
    and doesn't reduce cpu usage.

    I have tried to correct by exiting the ondata event if called by itself
    with :

             if sender = self then exit;

    but this does not seem to work. Perhaps I am doing this wrong?

    If you've read all of this you are very kind!

    Any solutions?


  • Next message: Jamie: "Re: listview"