1

I have a TListView (actually, a custom descendant) display in ViewStyle vsReport. One row is selected. I would like to get the screen coordinates of that row (or a cell within that row). Is there any way for me to do this?

(My goal is to display a small form over the list view giving the effect that it dropped down from the selected row).

I am using Delphi 2010 for this particular application.

Larry Lustig
  • 49,320
  • 14
  • 110
  • 160

2 Answers2

3

For a list view in vsReport style I believe the best approach is to use the LVM_GETITEMRECT and LVM_GETSUBITEMRECT messages.

The VCL does not wrap this functionality up for you but it should not be too difficult to work it out from the MSDN docs.

Whilst it is very simple to use the TListItem.Position property exposed by the VCL, as far as I can tell this does not help you obtain the row height or indeed the coordinates of sub items.

Update

As NGLN very helpfully points out, the CommCtrl unit does expose ListView_GetItemRect and ListView_GetSubItemRect which are more convenient to use than the equivalent Windows messages above.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 1
    @Larry For an example of its use: see [Draw own progress bar in ListView](http://stackoverflow.com/questions/7044125/delphi-draw-own-progress-bar-in-list-view/7048062#7048062). – NGLN Oct 31 '11 at 17:04
  • @NGLN Thanks. Good work. I see your update at the other question and upvoted it. Looks very nice indeed. – David Heffernan Oct 31 '11 at 17:09
0
var
  sel: TListItem;
  pnt: TPoint;
begin
  sel := ListView1.Selected;
  if not Assigned(sel) then Exit;
  pnt := ListView1.ClientToScreen(Sel.Position);
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384