-
[VERY URGENT!]Debug This Code![PLEASE]
I need some help with this script. It's not working....
VB Code:
Private Sub LoadFavorites()
'Set up the treeview
tvFavorites.Nodes.Clear()
tvFavorites.Nodes.Add("Favorites")
tvFavorites.Nodes(0).ImageIndex = 10
tvFavorites.Nodes(0).SelectedImageIndex = 10
Dim FavPath() As String
Dim strsplit() As String
Dim strFav As String
Dim i As Short
Dim oNode As TreeNode
Try
'Load Folders from Favorites Root
FavPath = Directory.GetDirectories(GetFolderPath(SpecialFolder.Favorites))
For Each strFav In FavPath
oNode = New TreeNode
strsplit = Split(strFav, "\", , CompareMethod.Text)
i = UBound(strsplit)
oNode.ImageIndex = 18
oNode.SelectedImageIndex = 19
oNode.Text = strsplit(i)
oNode.Tag = strFav
tvFavorites.Nodes(0).Nodes.Add(oNode)
LoadSubFolders(oNode, strFav)
Next
FavPath = Directory.GetFiles(GetFolderPath(SpecialFolder.Favorites))
For Each strFav In FavPath
If InStr(strFav, ".ini", CompareMethod.Text) Then
Else
oNode = New TreeNode
Dim oFile As New FileInfo(strFav)
strsplit = Split(oFile.Name, ".url", , CompareMethod.Text)
oNode.Text = strsplit(0)
oNode.ImageIndex = 16
oNode.SelectedImageIndex = 16
oNode.Tag = GetUrl(strFav)
tvFavorites.Nodes(0).Nodes.Add(oNode)
End If
Next
Catch ex As Exception
Catch ex As DirectoryNotFoundException
Catch ex As IO.IOException
End Try
oNode = Nothing
End Sub
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
Where is the error at?? We need more info.. what line?
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
With the tvFavorites.Nodes and the GetFolderPath.
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
Im guessing this is code you found?? You first need a treeview control on your form, called tvFavorites...
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
FavPath = Directory.GetDirectories(GetFolderPath(SpecialFolder.Favorites))
Nowhere do you have specialfolder.favorites defined... and the directory is not declared..
Directory example...
VB Code:
Dim MyDirectory As New System.IO.DirectoryInfo("Directory path")
After you declare your directory, THEN you can call .GetDirectories, and .GetFiles..
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
I have a treeview named that. It's the nodes thats messing it up.
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
Jeez...what is the error?!
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
I just copied a treeview in my form, and ran the following code:
VB Code:
'in button click
LoadFavorites()
'sub in form
Private Sub LoadFavorites()
'Set up the treeview
tvFavorites.Nodes.Clear()
tvFavorites.Nodes.Add("Favorites")
tvFavorites.Nodes(0).ImageIndex = 10
tvFavorites.Nodes(0).SelectedImageIndex = 10
End Sub
All worked fine... I repeat.. are you SURE you have a treeview control NAMED tvFavorites in the SAME form you are calling the LoadFavorites sub from?
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
And here is your code I modified on my machine, currently it loads what is in my "c:\" directory and adds them to the listbox... There were other things not shown in your code, that wern't defined, or defined elsewhere... (certain lines are commented out for a reason, in order to post a working example...)
VB Code:
Private Sub LoadFavorites()
'Set up the treeview
tvFavorites.Nodes.Clear()
tvFavorites.Nodes.Add("Favorites")
tvFavorites.Nodes(0).ImageIndex = 10
tvFavorites.Nodes(0).SelectedImageIndex = 10
Dim FavPath() As String
Dim strsplit() As String
Dim strFav As String
Dim i As Integer
Dim oNode As TreeNode
Dim MyDirectory As System.IO.Directory
Try
'Load Folders from Favorites Root
FavPath = MyDirectory.GetDirectories("C:\")
For Each strFav In FavPath
oNode = New TreeNode()
strsplit = Split(strFav, "\", , CompareMethod.Text)
i = UBound(strsplit)
oNode.ImageIndex = 18
oNode.SelectedImageIndex = 19
oNode.Text = strsplit(i)
oNode.Tag = strFav
tvFavorites.Nodes(0).Nodes.Add(oNode)
'LoadSubFolders(oNode, strFav)
Next
FavPath = MyDirectory.GetFiles("C:\")
For Each strFav In FavPath
If InStr(strFav, ".ini", CompareMethod.Text) = 1 Then
Else
oNode = New TreeNode()
Dim oFile As New System.IO.FileInfo(strFav)
strsplit = Split(oFile.Name, ".url", , CompareMethod.Text)
oNode.Text = strsplit(0)
oNode.ImageIndex = 16
oNode.SelectedImageIndex = 16
'oNode.Tag = GetUrl(strFav)
tvFavorites.Nodes(0).Nodes.Add(oNode)
End If
Next
Catch ex As Exception
'Catch ex As DirectoryNotFoundException
Catch ex As IO.IOException
End Try
oNode = Nothing
End Sub
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
Nice...thanks a bunch. However, it's still having trouble with the tvFavorites.Nodes
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
what is the error? Tough to fix if we dont know.
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
'Nodes' is not a member of 'System.Windows.Forms.ListView'.
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
Why are you calling the node property in listview? Listview has no node property only treeview has it.
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
Im not too sure. It was just in the example i found. Any way around it?
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
Once again... you need to have a TREEVIEW... not a LISTVIEW named tvFavorites.....
If you ADD A TREEVIEW instead of a LISTVIEW it will WORK! lol.. don't know how many times we have to say it...
Notice in the comments in the code...
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
Ok mr.fancy pants. Debug this one.
Quote:
If Not CurNode.Tag = Nothing Then
Process.Start(CurNode.Tag)
End If
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
Though not in your previous code, the "Tag" is an option for each item of the treeview. They are simply running then current node's tag (a variable they declared) in a Process.Start command...
Example.....
VB Code:
Dim CurNode As TreeNode
CurNode.Tag = tvFavorites.Nodes(0).Tag
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
OK then. So
VB Code:
Dim CurNode As TreeNode
CurNode.Tag = tvfavorites.Nodes(0) .Tag
will do the same as the messed up code that i had?
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
No, not sure what they are putting as a tag.. the code above doesn't add a tag to the treeview items, so you would get an error.
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
What would be a treeview tag?
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
-
Re: [VERY URGENT!]Debug This Code![PLEASE]
if you give us a description of what you are trying to accomplish exactly, we can try to give you better suggestions... I'm not sure where this tag code popped up, and why you are trying to use it, as it was not in your original post...