2007. május 16., szerda

Check which subitem of a TListView's ListItem was clicked (2)


Problem/Question/Abstract:

Is it possible to activate the click or double-click event for the subitems of a listview item? If yes, how can I do it?

Answer:

uses
  CommCtrl;

{$R *.dfm}

procedure TForm1.ListView1Click(Sender: TObject);
var
  pt: TPoint;
  item: TLIstItem;
  hittestinfo: TLVHitTestInfo;
begin
  pt := listview1.ScreenToClient(mouse.cursorpos);
  item := listview1.GetItemAt(pt.x, pt.y);
  if assigned(item) then
    memo1.Lines.add('Hit on item ' + item.Caption)
  else
  begin
    FillChar(hittestinfo, sizeof(hittestinfo), 0);
    hittestinfo.pt := pt;
    if - 1 <> listview1.perform(LVM_SUBITEMHITTEST, 0, lparam(@hittestinfo)) then
    begin
      memo1.lines.add(format('Item: %d (%s), subitem: %d (%s)', [hittestinfo.iItem,
        listview1.items[hittestinfo.iItem].caption, hittestinfo.iSubItem,
          listview1.items[hittestinfo.iItem].Subitems[hittestinfo.iSubItem - 1]]));

    end
    else
      memo1.lines.add('Not on item or subitem');
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése