Solved

Mouse over items in TListview

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

13 Experts available now in Live!

Get 1:1 Help Now