I can see both the image and the text for a split second but then the
window blinks and the text is gone. The image is still there. Then,
if I move the cursor over each listview item, the text reappears.
I can make the text disappear again by simply dragging another window
over it. Once again, moving the cursor over the listview item will
bring it back.
Anybody seen this before? I have traced it and logged stuff and I
cannot figure out what's going on. If I remove the draw code and just
go back to setting the item caption and image index, it is fine.
Here's the code:
procedure TForm1.OnData(Sender: TObject; Item: TListItem);
var ix : integer;
rect : TRect;
begin
rect := Item.DisplayRect(drSelectBounds);
ImageList1.Draw(listView1.Canvas, Rect.Left, Rect.Top, Item.Index);
listView1.Canvas.TextOut(Rect.Left+ImageList1.Width+2, Rect.Top,
'dummy text');
end;
Any help will be greatly appreciated.
STeve
> In the OnData event I draw an image from a imagelist
You should not be doing that in the OnData event. The Canvas is not
guaranteed to be valid during that event. That event is supposed to only
fill in the provided TListItem and nothing else. Any drawing should be done
in the drawing events instead and nowhere else.
> I can see both the image and the text for a split second but
> then the window blinks and the text is gone.
That suggests to me that you are not managing the text properly. Please
show your actual code.
> If I remove the draw code and just go back to setting the item
> caption and image index, it is fine.
As well it should be, because that is what you are supposed to be doing to
begin with.
> Here's the code:
That code is compleely wrong for that event.
Gambit
I was trying to use the OnData event because it is the only I can get
to fire. The OnDrawItem, which I am under the impression is the one
that fires only if OwnerDraw is set to true, does not seem to fire at
all. Since I had OwnerData set so I could make the listview virtual,
I tried OnData.
Any ideas what I should do to get the OnDrawItem to fire? When I get
that to work, should I just take out the OnData?
Thanks.
Steve
> I was trying to use the OnData event because it is the only
> I can get to fire.
The drawing events work just fine. I have used custom-drawn virtual
ListViews before and the events worked as expected.
> The OnDrawItem, which I am under the impression is the one
> that fires only if OwnerDraw is set to true, does not seem to fire at
> all.
Yes, it does. Alternatively, have you considered one of the other drawing
events? OnCustomDrawItem and OnAdvancedCustomDrawItem do not use the
OwnerDraw property.
> Any ideas what I should do to get the OnDrawItem to fire?
It should be firing just fine.
> When I get that to work, should I just take out the OnData?
That depends on why you are using a virtual list view to begin with. How
many items are you trying to display?
Gambit
Yes, the other drawing events do seem to work fine, just the
OnDrawItem does not fire. I guess I could try one of the others, but
I thought OnDrawItem was supposed to fire at exactly the right time in
the rendering process to draw the items. I agree it *should be*
firing just fine, but I have put in various combinations of
showmessage commands and a log file write and the code to draw the
image and the text and stepped through it with debug and it does not
fire.
I could potentially be listing 1000's of items and thumbnails so I
think a virtual listview is in order. I want to stay with that but am
questioning if I am filling the cell in my draw event, why I need to
do anything with an OnData event.
Steve
Why OnDrawItem is not firing, I don't know, and I will open a separate
thread on that and maybe an incident with Borland although my fervor
is tempered somewhat by finding a workaround.
Thanks Remy for your replies.
Steve
On Sun, 22 Jan 2006 19:12:11 -0600, Steve <swll773@hotmailnospam_.net>
wrote:
> having OwnerDraw set to true keeps the control from
> trying to render the cell
The event handler has a DefaultDraw parameter for that.
Gambit
So what's the point of setting OwnerDraw at all? OnDrawItem doesn't
fire and DefaultDraw can keep the cell from being drawn (although the
documentation says DefaultDraw only affects the text, not the image).
> So what's the point of setting OwnerDraw at all?
The DefaultDraw parameter in the drawing events can be set conditionally on
a per-item basis, whereas the OwerDraw property effects the entire TListView
as a whole.
> OnDrawItem doesn't fire
Yes, it does. I tried it and it works fine for me. The OwnerDraw property
enables the LVS_OWNERDRAWFIXED style, which in turn causes the ListView to
receive WM_DRAWITEM messages, which then triggers the OnDrawItem event when
received.
Gambit
>
>"Steve" <swll773@hotmailnospam_.net> wrote in message
>news:llfdt1pms7qpoaqd6...@4ax.com...
>
>> So what's the point of setting OwnerDraw at all?
>
>The DefaultDraw parameter in the drawing events can be set conditionally on
>a per-item basis, whereas the OwerDraw property effects the entire TListView
>as a whole.
But still, DefaultDraw is just for the text, not the image, correct?
>> OnDrawItem doesn't fire
>
>Yes, it does. I tried it and it works fine for me. The OwnerDraw property
>enables the LVS_OWNERDRAWFIXED style, which in turn causes the ListView to
>receive WM_DRAWITEM messages, which then triggers the OnDrawItem event when
>received.
>
>
It doesn't fire in my application in Delphi 2005 update 3. I may have
done something or have some conflicting event to prevent it but I
don't know what that would be. I will dummy up a very simple
listview app and try it there and see what I get.
> But still, DefaultDraw is just for the text, not the image, correct?
No. It is for everything.
> It doesn't fire in my application in Delphi 2005 update 3.
It works fine for me in D6 and earlier, so I would suspect Borland changed
the way TListView operates in newer versions.
Gambit
>
>
>It works fine for me in D6 and earlier, so I would suspect Borland changed
>the way TListView operates in newer versions.
>
TeamB? Is that like Team Borland? And you are still on D6? Should
that tell me something?
Regardless, thanks for the input. I am going to play around with this
some more and file a bug report (or whatever one does) with Borland if
it does not work. The doc says it should... Thanks again.
Steve
> TeamB? Is that like Team Borland?
> And you are still on D6?
Actually, I do most of my development in BCB 5 and 6, but the VCL is the
same in both Delphi and C++ for the cooresponding versions..
Gambit