Solved

Mouse over items in TListview

Posted on 2003-11-16
4
553 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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