我有一个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中的项设置标签标题。
请帮我改正我的密码。
发布于 2020-01-23 10:06:42
看起来你在寻找LV.Items[i].Caption和LV.Items[i].SubItems[j]。
Caption是最左边的cell.SubItems[0],SubItems[1]中的文本,. SubItems[LV.Columns.Count - 2]在剩下的单元格中生成文本。所以,在您的例子中,给定行i,
LV.Items[i].Caption是"RN“中的值,column.LV.Items[i].SubItems[0]是"RC”中的值,column.LV.Items[i].SubItems[1]是"RFD“中的值,column.LV.Items[i].SubItems[2]是"RUR”中的值,column.LV.Items[i].SubItems[3]是"RID“中的值,column.LV.Items[i].SubItems[4]是"isV”列中的值。https://stackoverflow.com/questions/59875823
复制相似问题