Solved

Mouse over items in TListview

Posted on 2003-11-16
4
534 Views
Last Modified: 2010-05-18
I have a listview containing some items. When I move the mouse over a specific item I want
some things to happen. I see that TListView has a MouseMove event that I can use, but I'm not
sure about the code. I want it to be something like this (pseudo-code):
 
procedure TMainForm.ListView1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
var mOverItem: integer;
 
//code for finding out which item the mouse is over. Stored in mOverItem. -1 if none.
 
//calls a procedure with the mOverItem as a parameter. don't worry about this one. I can handle this myself.
 
end;
 
is this possible?
the listview can have different number of items.

cheers,
mha
0
Comment
Question by:michaenh
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 125 total points
ID: 9762052
maybe ?

procedure TForm1.ListView1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var mOverItem: TListItem;
begin
  mOverItem := ListView1.GetItemAt(x,y);
  if mOverItem.Index = ....
  //or
  if mOverItem.Caption = ....

end;


meikl ;-)
0
 

Author Comment

by:michaenh
ID: 9762115
I did something like this:
 
procedure TMainForm.ListView2MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
mOverItem: TListItem;
begin
try
mOverItem := ListView1.GetItemAt(x,y);
label1.Caption := IntToStr(mOverItem.Index);
except on e: exception do
 
end;
end;

but my label only shows '0' when I hold my mouse over the first item. It doesn't react when i'm holding over the other items.
if i put a showmessage(e.message) in my except block i just get an access violation error. but it's then mOverItem.index that generates the exception I believe.
btw, my items have just image. their caption is blank.

thanks
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9762153
tested:

procedure TForm1.ListView1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  mOverItem: TListItem;
begin
  mOverItem := ListView1.GetItemAt(x,y);
  if assigned(mOverItem) then  //<--- you must do a test
    label1.Caption := inttostr(mOverItem.Index);


end;

meikl ;-)
0
 

Author Comment

by:michaenh
ID: 9762241
It worked!
My apologies but, I didn't see that I tried to get the ListView1.index in the ListView2 mousemove :=)

procedure TMainForm.ListView1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
mOverItem: TListItem;
begin
try
mOverItem := ListView1.GetItemAt(x,y);
SkrivForklaring(mOverItem.Index, ListView1);
except on e: exception do
SkrivForklaring(-1, ListView1);
end;
end;

thanks for your quick response! :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 259
creating manifest for my dll that called from activex 6 98
Printing problem 2 79
JAudiorecorder record freezing the app 29 59
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now