在Form1上放置ProgressBar1,ListView1,Button1各一个,部分代码如下:
procedure TForm1.Button1Click(Sender: TObject);
begin
AddLVItem('aa', 'bb', '', ListView1);
ProgressBar1.Parent := ListView1; //关键在此
ProgressBar1.Top := 20; //位置(如果有多个则最好用变量)
ProgressBar1.Left := 150;
end;
procedure TForm1.AddLVItem(sCap, str1, str2: string; aLV: TListView);
var
NewItem: TListItem;
begin
NewItem := aLV.Items.Add;
with NewItem do
begin
Caption := sCap;
SubItems.Add(str1);
SubItems.Add(str2);
end;
end;