How to display Tlistview hints

I am using Tlistview writing a report, my questions is how
to display differents hints when mouse point to differents rows.
Example:

Description            Price                where to buy
=========       =========       ===========
Kodak DC210      USD 110.00         Ebay
Kodak DC220      USD 220.00         Ebay
Kodak DC230      USD 300.00         Ebay
.
.
.

When I use mouse point to Kodak DC210, I want to display
a full feature descriptions of Kodak DC210 as hints. and when
point to Kodak DC220, display Kodak DC220's features, and
when point to Kodak DC230, display Kodak DC230's features

How to do it? I am using Tlistview.

Thanks & Rgds

Shekou
shekouAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pedeCommented:
Hi Shekou

I've made something similar, try this:

Add the following variable as private, or public or whatever (to the form):

HintWnd : THintWindow;

On the form's create do this:

HintWnd := THintWindow.Create(Self);

Free it on the form's destroy:

HintWnd.Free;

Then try this on the ListView's mouseMove:

procedure TForm1.ListView1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
   Item    : TListItem;
   Rec     : TRect;
   HintStr : string;
begin
     Item := ListView1.GetItemAt(x,y);
     if (Item<>nil) then
     begin
        HintStr := 'You are pointing at: '+Item.Caption;
        Rec := HintWnd.CalcHintRect(640, HintStr, nil);
        OffsetRect(Rec, Form1.Left, Form1.Top+20);

        HintWnd.ActivateHint(Rec, HintStr);
     end
     else
         HintWnd.ReleaseHandle;
end;

There's one more thing, though. You need to call HintWnd.ReleaseHandle on the listView's mouseLeave. If you dont, the hint window might stay visible if you move the mouse very quickly out of the control.

Just a suggestion, good luck with it

Regards,
Pede

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shekouAuthor Commented:
Thank you very much pede, but it seems no onmouseleave in listview.

Thanks & Rgds

Shekou
0
pedeCommented:
Hi Shekou

I know :o( You will need to make a component (which inherits from TListView) to catch the mouseLeave message. If you dont know how to do this, I can probably guide you through.

Regards,
Pede
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

shekouAuthor Commented:
Please kindly guide me through.



Thanks & Rgds

Shekou
0
pedeCommented:
Ok, to make a new component, do the following (this is with Delphi5, similar to Delphi3 and 4, if I remember correctly):

Select Component/New Component from the menu

Select (or type) TListView as ancestor type

As classname you type whatever you will like the class to be called. TMyListView or something...

Palette page is where you want the component to be placed, in the component palette (the 'Standard, Additional, Win32, System'-thing). You can leave it at samples, which I believe is default.

A unit filename will be suggested for you. It is probably a good idea to make a directory called 'components' or the like, where you place your own components.

Click install.

Chose 'Install into new package'

Type a packagename. A package can contain several components. You could name it MyPackage... You dont need to supply a description, but do it if you please.

Click ok

Your new component should be installed under 'Samples', and you should be able to see the source code for it.

I have added some code to give you the desired event:

unit MyListview;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls;

type
  TMouseLeaveEvent = procedure(Sender: TObject) of object;

  TMyListview = class(TListView)
  private
    FOnMouseLeave : TMouseLeaveEvent;
    { Private declarations }
  protected
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    { Protected declarations }
  public
    { Public declarations }
  published
    property OnMouseLeave : TMouseLeaveEvent read FOnMouseLeave write FOnMouseLeave;
    { Published declarations }
  end;

procedure Register;

implementation

procedure TMyListView.CMMouseLeave(var Message: TMessage);
begin
    if Assigned(FOnMouseLeave) then
        FOnMouseLeave(Self);
end;

procedure Register;
begin
  RegisterComponents('Samples', [TMyListView]);
end;

end.

You now need to compile the component again. There might be a package window open (is has 'Package' in the caption bar). Here you can click compile. If it is not open, chose Component/Install component, and install into existing package. Package filename is the name you chose earlier, I suggested 'MyPackage'. If you cant find it, search for the filename.

After this you can select it from 'Samples' and drop it on your form.

Phew... Im never going to be a teacher, I guess... This was harder to explain than I thought. Please read about components and packages in the help files. You wont regret it.

If you cant get it to work, let me know, but please give it a try first ;)

Regards,
Pede
0
shekouAuthor Commented:
Great!

Thank you very much

Shekou
0
JohnnCommented:
pede,

I just tried your MouseLeave solution however I can't seem to get the notification.  I copied your unit and instructions exactly.

Thanks,

0
pedeCommented:
Hi Johnn

I know this works, so I dont know why you cant get it to work.

If you can give me some more details, maybe we can solve it.

Was the component installed properly? If you can select it from samples, then it is installed.

Does it have the new event, MouseLeave?

Regards,
Pede

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.