Reputation: 57
I have a ListView with a number of fields inside of it.
On the other side, I have a ScrollBox that I want to fill in with data from the ListView.
This is done by creating a dynamic panel that contains a set of Labels to represent the data on the panel.
unit Unit3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls,
PngImageList, Vcl.Menus,
Vcl.ComCtrls, siComp, Registry, System.ImageList, Vcl.ImgList,
Vcl.Imaging.pngimage, rkGlassButton;
type
TForm3 = class(TForm)
ScrollBox1: TScrollBox;
LV: TListView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
Pnl : TPanel;
LabName : TLabel;
LabId : TLabel;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
var
posX,posY : SmallInt;
I: Byte;
Item: TListItem;
begin
posX := 0;
posY := 0;
for I := 0 to LV.Items.Count -1 do
begin
Pnl := TPanel.Create(ScrollBox1);
Pnl.Parent := ScrollBox1;
Pnl.Left := posX -1;
Pnl.Top := posY -1;
Pnl.Width := ScrollBox1.Width;
Pnl.Height := 40;
Pnl.BorderStyle := bsNone;
Pnl.BevelInner := bvNone;
Pnl.BevelKind := bkNone;
Pnl.BevelOuter := bvNone;
Pnl.ParentBackground := false;
Pnl.Color := clWhite;
Pnl.Anchors := [akTop, akRight,akLeft];
posY := posY + Pnl.Height;
//-------------------
LabName := TLabel.Create(Pnl);
LabName.Parent := Pnl;
LabName.Top := 10;
LabName.Left := 40;;
LabName.Font.Size := 11;
LabName.Caption :=LV.Items; // ??? ListView (RN)
//--------------------
LabId := TLabel.Create(Pnl);
LabId.Parent := Pnl;
LabId.Top := 10;
LabId.Left := 100;;
LabId.Font.Size := 11;
Item := LV.Items;
LabId.Caption := LV.Items;; // ??? ListView (RC)
end;
end;
end.
The panel is well constructed, but I do not know how to set the label captions using items in the ListView.
Please help me to correct my code.
Upvotes: 1
Views: 193
Reputation: 108948
It seems like you are looking for LV.Items[i].Caption
and LV.Items[i].SubItems[j]
.
Caption
is the text in the left-most cell.SubItems[0]
, SubItems[1]
, ..., SubItems[LV.Columns.Count - 2]
yield the texts in the remaining cells.So, in your case, given row i
,
LV.Items[i].Caption
is the value in the "RN" column.LV.Items[i].SubItems[0]
is the value in the "RC" column.LV.Items[i].SubItems[1]
is the value in the "RFD" column.LV.Items[i].SubItems[2]
is the value in the "RUR" column.LV.Items[i].SubItems[3]
is the value in the "RID" column.LV.Items[i].SubItems[4]
is the value in the "isV" column.Upvotes: 3