Contents
FileListBox  Sample Help

Sample Description: FileListBox

Points of Interest

Selecting a System Drive

Selecting a System Directory

Selecting Files

Control

FileListBox

FileComboBox

For Help on Help, Press F1


FileListBox

The purpose of this sample is to demonstrate the two types of controls that are available for selecting drives, directories, and files. The controls are:  FileListBox and FileComboBox. Each control is capable of only displaying drives, directories, or files. This is done by setting the following properties:

Property	Action

ShowDrives	Displays drives if set to True

ShowDirs	Displays directories if set to True

ShowFiles	Displays files if set to True

CurrentDir	Sets the currently selected directory

The FileListBox behaves very similar to the standard list box control. The ListCount property indicates how many files or directories are in the list, and ListIndex specifies the index of the currently selected list item. The SelPath property indicates the current path and filename or directory that is currently selected.

To use the FileListBox sample:

1.	Click on a drive letter.

2.	Then, double-click on a directory name that is displayed in the Directory FileListBox. A list of files in that directory will be displayed in the File FileListBox. In addition, a label at the bottom of the form will be updated to display the currently selected directory.


Selecting a System Drive

This sample uses a FileComboBox named cboDrives to select system drives. This control specializes in selecting Drives because the SelType property is set to "1 - Drives". When a specific Drive is clicked, the SelPath property is automatically updated. Clicking on this control invokes the following Click method which calls the following sub procedure.

Sub cboDrives_Click()

  ' Go to the selected drive/directory

  DisplayDir(cboDrives.SelPath)

End Sub

 Sub DisplayDir(ByVal dir As String)

  ' Setting list directory path has the side effect of

  ' resetting the lstDirectory.SelPath to ""

  ' Since DisplayDir is called sending this value, we need

  ' to use ByVal to explicitly copy the SelPath value.

  lstDirectory.Path = dir

  lstFiles.Path = dir

  cboDrives.SelectDrive(lstDirectory.Path)

  lblPath.Text = lstDirectory.Path

End Sub

This method sets the Path property of the lstDirectory (FileListBox) to be the Drive chosen. This automatically updates the contents of the FileListBox to include all main directories on that drive. In addition, the label lblPath on the form is updated to display the current drive and directory information.


Selecting a System Directory

This sample uses a FileListBox named lstDirectory to select and change directories. This control specializes in selecting Directories because the ShowDirs property is set to True. To prevent Drives and Files from being included, the ShowDrives and ShowFiles properties are set to False. The property SelPath displays the current working directory. The following Double-Click event is assigned to the lstDirectory control:

Sub lstDirectory_DblClick()

  ' Go to the selected directory

  DisplayDir(lstDirectory.SelPath)

End Sub

As shown by the above code, when a directory is double-clicked in the lstDirectory control, an additional FileListBox control is updated with the SelPath information. This control is named: lstFiles. The lstFiles FileListBox has its ShowFiles property set to True. Each time the SelPath property is set, a list of files from that directory are displayed.

Basically what this sample is doing is organizing the files and directories in two FileListBoxes each time a directory is clicked by the user. It is important to note that the lstFiles control has its Filter property set to ".", which means that all files will be displayed. To change this to accept specific file formats simply add a format to this Filter property. All files shown in this list will end up in the lstFiles FileListBox for user selection.


Selecting Files

Selecting Files from the lstFiles FileListBox is a matter of clicking on a filename. Each time you click on a filename from the lstFiles FileListBox, the SelPath property is updated to reflect the name and path of the chosen file. This name can then be used by program code to perform some type of file operation.