给你个我用ListView控件显示某个目录下文件的例子,看看有无帮助吧.
我的ListView有两个Columns,一个FILENAME,另外一个FILE SIZE.
Procedure RefreshListView(PathDir: String; ListV: TListView);
Var
sr: TSearchRec;
ListItem: TListItem;
SizeStr: String;
Begin
ListV.Items.BeginUpdate ;
ListV.Items.clear;
If PathDir[Length(PathDir)]<>'/' Then
PathDir := PathDir+'/';
If FindFirst(PathDir+'*.*', $27, sr)=0 Then
Begin
ListItem := ListV.Items.add;
ListItem.caption := sr.Name;
SizeStr := Format('%.2fK', [sr.Size/1024.0]);
ListItem.SubItems.add(SizeStr);
While FindNext(sr)=0 Do
Begin
ListItem := ListV.Items.add;
ListItem.caption := sr.Name;
SizeStr := Format('%.2fK', [sr.Size/1024.0]);
ListItem.SubItems.add(SizeStr);
End;
End;
ListV.Items.EndUpdate ;
End;