Vermutlich geht's irgendwie viel schöner - aber ich hätte das hier anzubieten:
Delphi-Quellcode:
function GetSubItem(Listview: TListview; X, Y: Integer): Integer;
// Requires unit "CommCtrl"
var
HitTest: TLVHitTestInfo;
begin
result := -1;
with HitTest
do
begin
pt.X := X;
pt.Y := Y;
If (Listview.perform( LVM_SUBITEMHITTEST, 0, lparam(@HitTest)) <> -1)
then begin
result := HitTest.iSubItem;
end;
end;
end;
procedure TSampleForm.ListviewClick(Sender: TObject);
var ListViewCursosPos: TPoint;
ColumnIndex: Integer;
begin
ListViewCursosPos := TListView(Sender).ScreenToClient(Mouse.CursorPos);
ColumnIndex := GetSubItem(TListView(Sender), ListViewCursosPos.X, ListViewCursosPos.Y);
if ColumnIndex>-1
then begin
showmessage(TListView(Sender).Column[ColumnIndex].Caption);
end;
end;