Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 39,535 times

Contents

Related Categories

Drive Combo, Folder and File List Controls - Files & Folder ListBoxes

Files & Folder ListBoxes

Again, both the file and folder list boxes have almost identical properties to the listbox. You can get the selected items using the Selected property, and set the selection using the ListIndex property. For more information on these standard listbox properties, click here.

To set the path that the file lists the files from, simply set its Path property. The following code sets the file list box to display files in "C:Program Files"

Files1.Path = "C:Program Files"

To set the current folder for the folder listbox, or to change the drive, you set the Path property, just like the file listbox:

'set the folder to C:Program Files
Dir1.Path = "C:Program Files"
'change to floppy
Dir1.Path = "A:"

However, you would obviously need to make sure there was a floppy in Drive A before switching to it. The next section covers how to use the three controls together, and shows you how to add some error handling code to display a warning if there is no floppy in the drive, rather than your program displaying an error message and quitting!

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Houston, we have a problem...

    Posted by HyperHacker on 28 Jul 2003

    When I try to set the drive list's drive back to the previous one, it shows me that drive in the dir/file boxes, but the drive selector remains at the drive the user selected. Any way to fix it? (Usin...

  • Thank you VERY much!

    Posted by Knoj on 30 May 2003

    I am a beginner, and I found your article VERY easy to use, and it saved me alot of time on my project! Thank you again, and I have a small possibly un-nessary, but usefull addition to one line of yo...