-1

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;
LU RD
  • 34,438
  • 5
  • 88
  • 296
DelphiStudent
  • 384
  • 1
  • 7
  • 23
  • So, this is FMX... Where is the gray panel in your picture ? Is it that 1 or 2 pixel high line you're pointing with the arrow ? Have you tried to set `Bottom` to the panel's `Align` property ? – TLama May 15 '15 at 10:37
  • this is a vcl application @TLama i created listview and draw some gradient on it , what iam trying to do is align this 1 pixel line to a buttom of my actual item height – DelphiStudent May 15 '15 at 10:40
  • I would say, then draw that line to the bottom of the item rectangle. But I cannot, because there's this panel thing. So you have a panel parented to a list view item (what ?) ? Or what's all this about ? – TLama May 15 '15 at 10:44
  • ok , i will describe , first i dont want to draw lines under all items , this 1 pixel panel is none visible by default until some of the clients of this application click on some button to mark him self with this line under his item – DelphiStudent May 15 '15 at 10:45
  • 1
    Oh, so it's not a `TPanel` control, but something you just call panel. But why do you set to that `Panel1` thing `Top` property ? I'm afraid I still cannot make any sense of this. The item rendering events provide you the content rectangles, so take them and render near their `Bottom`. – TLama May 15 '15 at 10:50
  • actual code added for better understand – DelphiStudent May 15 '15 at 10:52
  • Still makes no sence. You want to draw a line under each item? – Jens Borrisholt May 15 '15 at 10:54
  • That didn't help (to me). I feel that you're doing this wrong. There are events like `OnDrawItem` where you can render the items by yourself. You're not supposed to *cover* the list view with another controls. – TLama May 15 '15 at 10:54
  • hmmm , possibly i do it in very wrong way i will try to digging more . – DelphiStudent May 15 '15 at 10:56
  • You want to draw a line under each item? A question with two posible answers: A)Yes b) No – Jens Borrisholt May 15 '15 at 10:57
  • @JensBorrisholt no , i want to draw line on specif item if you see the for loop up there – DelphiStudent May 15 '15 at 10:59
  • Have a look at the CustomDrawItem event – Jens Borrisholt May 15 '15 at 11:09
  • The CustomDrawItem event does not have a rectangle to get the postion from. OnDrawItem would be ideal but is not called with TListView in this format. I know how to do it with TListBox - that is relatively easy, but I don't see an easy way to do it with TListView. – Dsm May 15 '15 at 11:29

2 Answers2

2

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.

SilverWarior
  • 7,372
  • 2
  • 16
  • 22
0

Take a new form, copy this code and paste it onto the form

object ListView1: TListView
  Left = 0
  Top = 40
  Width = 250
  Height = 296
  Anchors = [akLeft, akTop, akRight, akBottom]
  Columns = <>
  TabOrder = 0
end
object Panel1: TPanel
  Left = 0
  Top = 0
  Width = 250
  Height = 41
  Anchors = [akLeft, akTop, akRight]
  Caption = 'Panel1'
  TabOrder = 1
end

First I arrange the two objects at designtime. Then I set anchors on both objects.

Jens Borrisholt
  • 6,174
  • 1
  • 33
  • 67