delphi:vcl-如何从列表视图项填充ScrollBox

问题描述 投票:0回答:1

我内部有一个ListView字段数

另一方面,我有ScrollBox

我想通过ListView中的数据填写ScrollBox

这是通过创建一个动态面板来完成的,该面板包含一组用于表示面板上数据的标签enter image description here

    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中的项目

请帮助我更正我的代码

谢谢

delphi vcl
1个回答
0
投票
似乎您正在寻找LV.Items[i].CaptionLV.Items[i].SubItems[j]

    [Caption是最左侧单元格中的文本。
  • [SubItems[0]SubItems[1],...,SubItems[LV.Columns.Count - 2]产生其余单元格中的文本。
© www.soinside.com 2019 - 2024. All rights reserved.