30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

554 Graphical User Interfaces Concepts: Part 2 Chapter 13<br />

25<br />

26 If direc<strong>to</strong>ryArray.Length 0 Then ' if at least one<br />

27<br />

28 Dim currentDirec<strong>to</strong>ry As String<br />

29<br />

30 ' for every subdirec<strong>to</strong>ry, create new TreeNode,<br />

31 ' add as child of current node and<br />

32 ' recursively populate child nodes with subdirec<strong>to</strong>ries<br />

33 For Each currentDirec<strong>to</strong>ry In direc<strong>to</strong>ryArray<br />

34<br />

35 ' create TreeNode for current direc<strong>to</strong>ry<br />

36 Dim myNode As TreeNode = _<br />

37 New TreeNode(currentDirec<strong>to</strong>ry)<br />

38<br />

39 ' add current direc<strong>to</strong>ry node <strong>to</strong> parent node<br />

40 parentNode.Nodes.Add(myNode)<br />

41<br />

42 ' recursively populate every subdirec<strong>to</strong>ry<br />

43 PopulateTreeView(currentDirec<strong>to</strong>ry, myNode)<br />

44 Next<br />

45<br />

46 End If<br />

47<br />

48 ' catch exception<br />

49 Catch unauthorized As UnauthorizedAccessException<br />

50 parentNode.Nodes.Add("Access Denied")<br />

51 End Try<br />

52<br />

53 End Sub ' PopulateTreeView<br />

54<br />

55 ' called by system when form loads<br />

56 Private Sub FrmTreeViewDirec<strong>to</strong>ry_Load(ByVal sender As Object, _<br />

57 ByVal e As System.EventArgs) Handles MyBase.Load<br />

58<br />

59 ' add c:\ drive <strong>to</strong> treDirec<strong>to</strong>ry and insert its subfolders<br />

60 treDirec<strong>to</strong>ry.Nodes.Add("C:")<br />

61 PopulateTreeView("C:\", treDirec<strong>to</strong>ry.Nodes(0))<br />

62 End Sub ' FrmTreeViewDirec<strong>to</strong>ry_Load<br />

63<br />

64 End Class ' FrmTreeViewDirec<strong>to</strong>ry<br />

Fig. 13.22 TreeView used <strong>to</strong> display direc<strong>to</strong>ries (part 2 of 3).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!