RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TFileListBox Class

TFileListBox is a specialized list box that lists all the files in a specified directory.

Pascal
TFileListBox = class(TCustomListBox);
C++
class TFileListBox : public TCustomListBox;

FileCtrl

Add TFileListBox to a form to allow users to select a file. Use TFileListBox along with TDriveComboBox, TFilterComboBox, and TDirectoryListBox to add full file selection capabilities to a form.

Note: To add a standard Windows file open or save dialog to an application, use TOpenDialog or TSaveDialog instead.
 

C++ Examples: 

 

/*
This example uses a file list box, a directory list box, and
a label on a form. When the user uses the directory list box
to change directories, a message appears and the color of
the form changes if the file AUTOEXEC.BAT is in the new
directory. The code is written in the OnChange event of the
directory list box:
*/
void __fastcall TForm1::DirectoryListBox1Change(TObject *Sender)
{
  FileListBox1->Directory = DirectoryListBox1->Directory;
  if (FileListBox1->Items->IndexOf("AUTOEXEC.BAT") > -1)
  {
    Color = clYellow;
    Label1->Caption = "You are in the root directory!";
  }
}

 

Delphi Examples: 

{
This example uses a file list box, a directory list box, and
a label on a form. When the user uses the directory list box
to change directories, a message appears and the color of
the form changes if the file AUTOEXEC.BAT is in the new
directory. The code is written in the OnChange event of the
directory list box:
}
procedure TForm1.DirectoryListBox1Change(Sender: TObject);
begin
  FileListBox1.Directory := DirectoryListBox1.Directory;
  if FileListBox1.Items.IndexOf('AUTOEXEC.BAT') > -1 then
  begin
    Color := clYellow;
    Label1.Caption := 'You are in the root directory!';
  end
  else
  begin
    Color := clBtnFace;
    Label1.Caption := '';
  end;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!