Solved

Mouse over items in TListview

Posted on 2003-11-16
4
562 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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