RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDirectoryListBox.OnChange Event

Occurs when the user selects a new directory with the mouse or keyboard when the user moves the selection bar and presses enter.

Pascal
property OnChange: TNotifyEvent;
C++
__property TNotifyEvent OnChange;

Write an OnChange event handler to perform an action whenever a new directory is selected.  

C++ Examples: 

 

/*
The following example assumes that a drive combo box, a file
list box, and a directory list box are on a form. Add this
code as the OnChange event handler for the drive combo box
and the OnChange event handler for the directory list box.
When the user changes the drive using the combo box, the
directory list box and file list box will update to reflect
the new drive and the current directory on that drive.  When
the user double clicks on a directory in the file list box
will update to reflect the new directory.
*/
void __fastcall TForm1::DriveComboBox1Change(TObject *Sender)
{
  DirectoryListBox1->Drive = DriveComboBox1->Drive;
  FileListBox1->Drive = DriveComboBox1->Drive;
  FileListBox1->Directory = DirectoryListBox1->Directory;
}

void __fastcall TForm1::DirectoryListBox1Change(TObject *Sender)
{
  FileListBox1->Directory = DirectoryListBox1->Directory;
}
/*
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: 

{
The following example assumes that a drive combo box, a file
list box, and a directory list box are on a form. Add this
code as the OnChange event handler for the drive combo box
and the OnChange event handler for the directory list box.
When the user changes the drive using the combo box, the
directory list box and file list box will update to reflect
the new drive and the current directory on that drive.  When
the user double clicks on a directory in the file list box
will update to reflect the new directory.
}
procedure TForm1.DirectoryListBox1Change(Sender: TObject);
begin
  FileListBox1.Directory := DirectoryListBox1.Directory;
end;

procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
  DirectoryListBox1.Drive := DriveComboBox1.Drive;
  FileListBox1.Drive := DriveComboBox1.Drive;
  FileListBox1.Directory := DirectoryListBox1.Directory;
end;
{
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!