Link to home
Start Free TrialLog in
Avatar of IT79637
IT79637Flag for United States of America

asked on

How to populate ListView control?

Hi,


I'm using D7 Ent. on a WinXP Pro SP3 box.

I've place a ListView1 control on a panel.  I am able to add headings and set column width, but do not understand how to add "data" under the headings.

My ListView1 has 3 columns.
1.   File Name, Original Size, Reduced Size.
2.   I want to populate the first two columns when I click Button1 (file name & file size).  
3.  Next, click Button2
     a. Do some work to do some work (procedure call which returns data for col 3. (file size after compression))
     b. Populate the 3rd column with the results of step 3.a..

Can I do this in two steps? How do I do it?

My code, so far, is below.

Thanks much!
.... 
procedure ListFiles(const AFolder, AFilter: string; AList: TStrings);

var
  NewColumn: TListColumn;
  ListItem: TListItem;

implementation
...
...
...
procedure TfResizeFiles.btnGetSetClick(Sender: TObject);
var
  sl : TStringList;
  strPath, strFilter : string;
  i  : integer;
  NewColumn: TListColumn;
  ListItem: TListItem;
begin
  strPath := Trim(edDrivePath.Text);  /have deleted code to verify directory exists, etc.
try  
  with ListView1 do
  begin
    ViewStyle := vsReport;

    NewColumn := Columns.Add;
    NewColumn.Width := 250;
    NewColumn.Caption := 'Image Name';
    NewColumn := Columns.Add;
    NewColumn.Width := 100;
    NewColumn.Caption := 'Original Size';
    NewColumn := Columns.Add;
    NewColumn.Width := 100;
    NewColumn.Caption := 'Reduced Size';
  end;
  sl := TStringList.Create;
   ListFiles(strPath, strFilter, sl.add.item)  // procedure is below.
 finaly
  sl.Free;
 end;
end;
===============================
procedure ListFiles(const AFolder, AFilter: string; AList: TStrings);
var
  vFindHandle: THandle;
  vFilter    : String;
  vFindData  : WIN32_FIND_DATA;
begin
  AList.BeginUpdate;
  try
    AList.Clear;
    vFilter := AFolder + '\' + AFilter;
    vFindHandle := FindFirstFile(PChar(vFilter), vFindData);
    if vFindHandle = INVALID_HANDLE_VALUE then
      Exit;

    repeat
      AList.Add(ChangeFileExt(vFindData.cFileName, ''));
    until not FindNextFile(vFindHandle, vFindData);

    Windows.FindClose(vFindHandle);
  finally
    AList.EndUpdate;
  end;
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial