I use Delphi 2007. I have a TListView with OwnerData and OwnerDraw set to True. ViewStyle is set to vsReport.
I have a record.
type TAList=record
Item:Integer;
SubItem1:String;
SubItem2:String;
end;
var
ModuleData: array of TAList;
procedure TForm1.ListView3Data(Sender: TObject; Item: TListItem);
begin
Item.Caption := IntToStr(ModuleData[Item.Index].Item);
Item.SubItems.Add(ModuleData[Item.Index].SubItem1);
Item.SubItems.Add(ModuleData[Item.Index].SubItem2);
end;
procedure TForm1.ListView3DrawItem(Sender: TCustomListView; Item: TListItem; Rect: TRect; State: TOwnerDrawState);
var
LIndex : integer;
LRect: TRect;
LText: string;
TTListView: TListView;
begin
TTListView := TListView(Sender);
if (Item.SubItems[0] = '...') then
begin
TTListView.Canvas.Brush.Color := clHighlight;
TTListView.Canvas.Font.Color := clHighlightText;
end else
begin
TTListView.Canvas.Brush.Color := TTListView.Color;
TTListView.Canvas.Font.Color := TTListView.Font.Color;
end;
for LIndex := 0 to TTListView.Columns.Count - 1 do
begin
if (not(ListView_GetSubItemRect(TTListView.Handle, Item.Index, LIndex, LVIR_BOUNDS, @LRect))) then Continue;
TTListView.Canvas.FillRect(LRect);
if (LIndex = 0) then LText := Item.Caption else LText := Item.SubItems[LIndex - 1];
LRect.Left := LRect.Left + 6;
DrawText(TTListView.Canvas.Handle, PChar(LText), Length(LText), LRect, DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX or DT_END_ELLIPSIS);
end;
end;
I wish to show an hint when SubItem2 is truncated. On Windows XP, no hint is shown at all. On Windows Vista & Windows 7, when my mouse is over an item, it shows an hint that is totally off.
I have no special code to handle hints. Should there be one in OwnerData and OwnerDraw modes?
Here are images of what I get:

(source: noelshack.com)

(source: noelshack.com)
EDIT:
David asked why OwnerDraw was set to True. There are two reasons:
- This way, I can "disallow" user selection.
- If I set
OwnerDrawtoFalse, I get another problem. See Why do I get white column separators on my custom-drawn listview?
EDIT 2:
If I handle the OnInfoTip event as suggested by TLama, I get an unthemed balloon hint and the wrong hint from Windows Vista & 7.
1. Environment
Behavior described here I’ve experienced and tested only on Windows 7 SP1 64-bit Home Premium with most recent updates installed with application built in Delphi 2009 also with latest updates applied. In no other system I’ve tried this.
2. About the problem
Default item hints that you can see on your screenshot doesn’t come from VCL. In certain circumstances whose you just hit, are those hints shown by the system in a wrong, probably somehow cached way. The text of the last item you hovered is shown as a hint for the item you’re just hovering. Here is the property configuration (just the important part; the rest I kept in default component values):
The following events are handled:
Actually, you don’t even need to handle the
OnDrawItemto simulate the problem. The hints are shown by the texts given to the items in theOnDataevent. I’m not able to trace it more deeper, since it seems there’s no notification handler (nor even system notification) that might be related to the hints you see in the VCL, which is the reason why I’m suspecting the system.3. The way to solution
Nothing what I’ve tried didn’t fix the problem keeping your current property configuration. Here’s a list of what I’ve tried:
3.1. Remove the LVS_EX_LABELTIP style ?
As a hot favorite and actually the first what I’ve checked was excluding the
LVS_EX_LABELTIPfrom the list view’s style in a hope the item hint showing will stop and you’ll be able to implement your own custom hints through theOnInfoTipevent. The problem is, that this style is not implemented anywhere in the list view control, thus it’s not included in the list view style.3.2. Disable the OwnerDraw property ?
Setting the
OwnerDrawproperty to False actually resolves the issue (hints are then shown with correct item texts by the actual hovered item), but you’ve said you need to use owner drawing, so it’s also not a solution for you.3.3. Remove the LVS_EX_INFOTIP style ?
Removing the
LVS_EX_INFOTIPstyle from the list view’s style finally stopped showing of the item hints by the system, but also caused that the control stopped to send to the parent the tooltip notifications. As a consequence of this is theOnInfoTipevent with its functionality cutted off. In this case you need to implement the hint handling completely by yourself. And that’s what I’ve tried in the following code.4. Workaround
I’ve decided to disable all the system hints of a list view by excluding of the
LVS_EX_INFOTIPstyle and implementing own tooltip handling. So far I know at least about the following problems:when you use a regular
Hintproperty and hover from an item with shortened caption to the empty area of a list view, theHintis shown, but it doesn’t hide unless you exit the control client rectangle or the hint show time interval elapses (even if you hover an item with shortened caption again). The problem is that I don’t know how to specify theCursorRectfor theTHintInfostructure, so that you cover the whole client rectangle except items area rectangle.you must use the same item rectangle extents as you use in your owner drawing event method since the system doesn’t know, where you’re rendering the text of your items. So, another disadvantage is to keep this in sync.
Here is the code of the main unit from a demo project, which you can download
from hereif you want: