5,392
社区成员
发帖
与我相关
我的任务
分享
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
this->ListView1->ViewStyle=vsIcon;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TListItem *li;
for(int i=1;i<=3;++i)
{
li=this->ListView1->Items->Add();
li->Caption=L"add"+IntToStr(i);
}
li=this->ListView1->Items->Insert(0);
li->Caption=L"insert0";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListView1Click(TObject *Sender)
{
this->Caption=IntToStr(this->ListView1->ItemIndex);
}
//---------------------------------------------------------------------------
var
I:Integer;
vt:TListItem;
begin
ListView1.Items.BeginUpdate;
for I := 1 to 4 do
begin
vt:=ListView1.Items.Add ;
vt.Caption:='t'+i.ToString;
end;
vt:=ListView1.Items.Insert(0);
vt.Caption:='0000';
ListView1.Items.EndUpdate;
加上BeginUpdate与EndUpdate,是可以的。