Visual Basic Concepts

Using File-System Controls Together

See Also

If you use a combination of file-system controls, you can synchronize the information they display. For example, if you have a drive list box, a directory list box, and a file list box with the default names Drive1, Dir1, and File1, the sequence of events might work like this:

  1. The user selects a drive in the Drive1 list box.

  2. A Drive1_Change event is generated, and the display in Drive1 is updated to reflect the new drive.

  3. Code in the Drive1_Change event procedure assigns the new selection (the Drive1.Drive property) to the Path property of the Dir1 list box with the following statements:
    Private Sub Drive1_Change ()
       Dir1.Path = Drive1.Drive
    End Sub
    
  4. The assignment to the Path property generates a Dir1_Change event and updates the display in Dir1 to reflect the current directory of the new drive.

  5. Code in the Dir1_Change event procedure assigns the new path (the Dir1.Path property) to the File1.Path property of the File1 list box:
    Private Sub Dir1_Change ()
       File1.Path = Dir1.Path
    End Sub
    
  6. The assignment to the File1.Path property causes the display in the File1 list box to reflect the Dir1 path specification.

The event procedures you use and the properties you change depend on the way your application uses the combination of file-system controls. The code in "File-System Controls Scenario: A File Seeker Application" illustrates the synchronization of controls described here.