如何从 ListView 项目填充 ScrollBox
How to fill a ScrollBox from ListView items
我有一个 ListView,里面有很多字段。
另一方面,我有一个 ScrollBox,我想用 ListView 中的数据填充它。
这是通过创建一个动态面板来完成的,该面板包含一组标签来表示面板上的数据。
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.
面板结构很好,但我不知道如何使用ListView 中的项目设置标签标题。
请帮我更正我的代码。
您似乎在寻找 LV.Items[i].Caption
和 LV.Items[i].SubItems[j]
。
Caption
是最左边单元格中的文本。
SubItems[0]
、SubItems[1]
、...、SubItems[LV.Columns.Count - 2]
生成剩余单元格中的文本。
因此,在您的情况下,给定行 i
,
LV.Items[i].Caption
是 "RN" 列中的值。
LV.Items[i].SubItems[0]
是 "RC" 列中的值。
LV.Items[i].SubItems[1]
是 "RFD" 列中的值。
LV.Items[i].SubItems[2]
是 "RUR" 列中的值。
LV.Items[i].SubItems[3]
是 "RID" 列中的值。
LV.Items[i].SubItems[4]
是 "isV" 列中的值。
我有一个 ListView,里面有很多字段。
另一方面,我有一个 ScrollBox,我想用 ListView 中的数据填充它。
这是通过创建一个动态面板来完成的,该面板包含一组标签来表示面板上的数据。
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.
面板结构很好,但我不知道如何使用ListView 中的项目设置标签标题。
请帮我更正我的代码。
您似乎在寻找 LV.Items[i].Caption
和 LV.Items[i].SubItems[j]
。
Caption
是最左边单元格中的文本。SubItems[0]
、SubItems[1]
、...、SubItems[LV.Columns.Count - 2]
生成剩余单元格中的文本。
因此,在您的情况下,给定行 i
,
LV.Items[i].Caption
是 "RN" 列中的值。LV.Items[i].SubItems[0]
是 "RC" 列中的值。LV.Items[i].SubItems[1]
是 "RFD" 列中的值。LV.Items[i].SubItems[2]
是 "RUR" 列中的值。LV.Items[i].SubItems[3]
是 "RID" 列中的值。LV.Items[i].SubItems[4]
是 "isV" 列中的值。