Home

VCL Controls: The Filter Combo Box

 

Introduction to the Filter Combo Box

 

Description

By default, a file list box is made to display all files from its parent directory. Depending on your application, you may want to show only some files, based on criteria of your choice. One of the criteria you can apply concerns file extensions. To apply this criterion, you can create a filter that you will apply to the file list box.

Practical LearningPractical Learning: Introducing the Directory List Box

  1. Start Embarcadero RAD Studio
  2. To create a new project, on the main menu, click File -> New -> VCL Forms Application - C++Builder
  3. Change the Caption of the form to File Viewer
  4. On the main menu, click File -> New -> Other
  5. On the main menu, click File -> New -> Other
  6. In the right list of the New Items dialog box, double-click Frame
  7. Notice the name on the tab of the new frame
  8. In the top section of the Code Edirtor, click Unit1.cpp
  9. In the Standard section of the Tool Palette, click Frame and click the form
  10. In the Select Frame to Insert dialog box, select the name of the new frame (it should be the last in the list) and click OK
  11. In the top section of the Code Editor, click the UnitX.cpp of the last frame
  12. In the Tool Palette, click Win 3.1
  13. Click the TDriveComboBox button Drive Combo Box and click inside the frame
  14. Press F9 to execute
  15. Click the down-point button of the drive combo box
  16. Close the form and return to your programming environment
  17. In the Win 3.1 section of the Tool Palette, click the TDirectoryListBox control Directory List Box and click inside the frame
  18. Adjust the design as follows:
     
    File Viewer
  19. On the Tool Palette, click Standard
  20. Click the TLabel control Directory List Box and click inside the frame under the directory list box
     
    File Viewer
  21. In the frame, click the directory list box to select it
  22. In the Object Inspector, click DirLabel and select Label1
  23. Press F9 to execute
  24. Change a drive in the combo box
  25. Close the form and return to your programming environment
  26. In the frame, click the drive combo box to select it
  27. In the Object Inspector, click DirList and select DirectoryListBox1
  28. Press F9 to execute
  29. Change a drive in the combo box
  30. Close the form and return to your programming environment
   

Creating a Filter Combo Box

To help you create a filter or a set of filters to apply to a file list box, the VCL provides the filter combo box. To visually create a filter combox, in the Win 3.1 section of the Tool Palette, click the TFilterComboBox control Filter Combo Box and click the form (or container). In the VCL, the filter combo box is represented by the TFilterCombBox class.

Practical LearningPractical Learning: Adding a Filter Combo Box

  1. In the Tool Palette, click Win 3.1
  2. Click the TFilterComboBox control Filter Combo Box and click inside the frame
  3. Adjust the design as follows:
     
    File Viewer

Using a Filter Combo Box

Before a filter combo box can play its role, you must create its filter(s). A filter is a string that is made of one or more internal sections. Each section is in the form:

File Category (*.Extension)|*.Extension

For the File category, enter a short description of the type of file. Provide an extension in the Extension placeholder(s). If you want to include more than one section, separate them with |. Here is an example:

HTML Files (*.htm)|*.htm|Perl Script (*.pl)|*.pl

To assist you with creating a filter, Embarcadero RAD Studio provides the Filter Editor dialog box.

Practical LearningPractical Learning: Creating a Filter

  1. In the frame, click the filter combo box
  2. In the Object Inspector, click Filter, then click its button
  3. Complete the Filter Editor as follows
     
    Filter Editor
  4. Click OK

Characteristics of the Filter Combo Box

 

The Filter to Apply

To support the filter, the TFilterComboBox class is equipped with a read-write property named Filter:

__property System::UnicodeString Filter = {read=FFilter,write=SetFilter};

Practical LearningPractical Learning: Applying a Filter

  1. In the frame, make sure the filter combo box is seleted.
    In the Object Inspector, click the FileList field and select FileListBox1
  2. Press F9 to execute
  3. Double-click a folder in the directory list box
  4. Close the form and return to your programming environment

The Filter of File List Box

To support the filter combo box, the TFilterComboBox class is quipped with a property named FileList:

__property Filectrl::TFileListBox * FileList = 
	{read=FFileList,write=SetFileListBox};

Once the filter combo box is ready, you can assign it to a file list box. In the Object Inspector, select the name of the file list box in the FileList field of the filter combo box.

 
 
 

Home Copyright © 2010-2011 FunctionX, Inc.