O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Fill a TreeView with a Just-In-Time Directory Tree

Problem

You need to show a directory tree with the TreeView control, but filling the directory tree structure at startup is too time consuming.

Solution

React to the BeforeExpand event to fill in subdirectories just before they are displayed.

Discussion

You can use the recursion technique shown in recipe Process Files Recursively to build an entire directory tree. However, scanning the file system in this way can be slow, particularly for large drives. For this reason, professional file management software (and Windows Explorer) use a different technique—they query the necessary directory information when the user requests it.

The TreeView control, shown in Figure 5-1, is particularly well suited to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required