|
-
March 4th, 2008, 02:19 PM
#1
TreeView errors
I follow an example on the book but got errors.
Thanks for help
Code:
Error 1 Value of type 'System.Windows.Forms.TreeNode' cannot be converted to 'System.Windows.Forms.TreeView'.
Error 2 Name 'directoryArray' is not declared.
FrmListBox
Code:
Imports System.Windows.Forms
Imports System.IO
Public Class Form1
Friend WithEvents trdDirectory As TreeView
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
trdDirectory.Nodes.Add("C:")
PopulateTreeView("C:\", trdDirectory.Nodes(0)) ' error 1 here
End Sub
Private Sub PopulateTreeView(ByVal directoryValue As String, ByVal parentNode As TreeView)
Try
Dim treDirectory As String() = Directory.GetDirectories(directoryValue)
If directoryArray.Length <> 0 Then 'error 2 here
Dim currentDirectory As String
For Each currentDirectory In directoryArray
Dim myNode As TreeNode = New TreeNode(currentDirectory)
parentNode.Nodes.Add(myNode)
PopulateTreeView(currentDirectory, myNode)
Next
End If
Catch unauthorized As UnauthorizedAccessException
parentNode.Nodes.Add("Access Denied")
End Try
End Sub
End Class
-
March 4th, 2008, 02:44 PM
#2
Re: TreeView errors
Well, you are getting error 1 because you are passing a treenode parameter to a sub that is expecting a treeview. Pass trdDirectory, not trdDirectory.Nodes(0).
You are getting error 2 because, well obviously, directoryArray is not declared, just like the error is telling you. I don't know what directoryArray is supposed to be from your current code, it is only reference in the one line.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|