Search code examples
delphilistviewitemdelphi-xe7

how do i align a tpanel to a very bottom of listview item


what i try to do is same as this image

enter image description here

thing i have tried panel1.top := ListView1.Items[i].position.Y;

but it didnt success with this trick , is there possibly way to aligned Tpanel at a bottom of some items

Actual code added

procedure Ttestthreading.streamClick(Sender: TObject);
var
  i, R: integer;
begin
  if stream.Caption = 'stream' then
  begin
    for i := 0 to ListView1.Items.Count - 1 do
      if ListView1.Items[i].SubItems[3] = IntToStr(UniqueID) then
      begin
        R := ListView1.Items[i].Index;
        panel2.Top := ListView1.Items[i].Position.Y;
      end;
    ExchangeItems(ListView1, R, 0);
    stream.Caption := 'stopstream';
    panel2.Visible := true;

    // start stream
  end
  else if stream.Caption = 'stopstream' then
  begin
    ExchangeItems(ListView1, R, 0);
    stream.Caption := 'stream';
    panel2.Visible := false;
    // stopstream

  end;
end;

Solution

  • If you check the documentation http://docwiki.embarcadero.com/Libraries/XE2/en/Vcl.ComCtrls.TListItem.Position you will see that TListitem.Position only works when ListView view style is either vsIcon or vsSmallIcon.

    So instead of using Position property you should rather use DisplayRect method http://docwiki.embarcadero.com/Libraries/XE2/en/Vcl.ComCtrls.TListItem.DisplayRect which returns the rectangle in which the List item is rendered.