![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Filling out a treeview on a form
Using vb2005, I have a treeview on a form, and I'm trying to populate the nodes with drives and directories and files. I got the drives to populate fine, but when it comes to directories, so far the best I can do is to have it populate the drives all over again for each drive listed when I double-click a node.
If I use the following code: For Each drv As Object In My.Computer.FileSystem.Drives()
tvwDir.Nodes(0).Nodes.Add(drv.ToString)
Next
For Each node As TreeNode In tvwDir.Nodes
For Each dir As Object In My.Computer.FileSystem.GetDirectories(node.Text)
If My.Computer.FileSystem.DirectoryExists(dir.ToString) Then
node.Nodes.Add(dir.ToString)
End If
Next
Next |
|
|
|
|
|
#2 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
I think I have it figured out now. Made the following changes:
For Each drv As Object In My.Computer.FileSystem.Drives()
If Not ((drv.ToString = "A:\") Or (drv.ToString = "D:\")) Then
tvwDir.Nodes(0).Nodes.Add(drv.ToString)
End If
Next
For Each node As TreeNode In tvwDir.Nodes(0).Nodes
For Each dir As Object In My.Computer.FileSystem.GetDirectories(node.Text)
node.Nodes.Add(dir.ToString.Substring(3, dir.ToString.Length - node.Text.Length))
Next
Next |
|
|
|
|
|
#3 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
I've filled out an imagelist for my treeview with 5 ico files. For some reason, I can only use 2 of those images, index 0,1, after those images I get an index out of range error. I set the treeview.imagelist = to my created imagelist as follows:
Dim imglst As New ImageList()
imglst.Images.Add(Image.FromFile("C:\Projects\File_Rename\computer.ico"))
imglst.Images.Add(Image.FromFile("C:\Projects\File_Rename\drive.ico"))
imglst.Images.Add(Image.FromFile("C:\Projects\File_Rename\folder1.ico"))
imglst.Images.Add(Image.FromFile("C:\Projects\File_Rename\folder2.ico"))
imglst.Images.Add(Image.FromFile("C:\Projects\File_Rename\file1.ico"))
tvwDir.ImageList = imglst
tvwDir.Nodes.Add("root", "My Computer")
tvwDir.Nodes.Item(0).ImageIndex = 0
tvwDir.Nodes(0).Nodes.Add(drv.ToString)
tvwDir.Nodes(0).Nodes.Item(drvindex).ImageIndex = 1
node.Nodes.Add(dir.ToString.Substring(3, dir.ToString.Length - 3))
node.Nodes.Item(dirindex).ImageIndex = 2The red part is where I'm getting the outside of index error. Is this because my files are not readable, or is it because there is a 2 index limit to an imagelist? The examples I've seen have many images in an imagelist. When I do just the first 2 indexes, it sets my root as the computer.ico, then the 2nd level nodes are set to drive.ico. All subsequent nodes are set to computer.ico. Don't worry about the semantics of my code, it's snippets relevant to the question extracted from the whole. |
|
|
|
|
|
#4 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Re: Filling out a treeview on a form
Above was fixed already, post was lost. It was a corrupt file
Ok, I've populated my treeview with drvnodes for drives, dirnodes for folders, and filenodes for files. I have a sub for nodeclick that does pretty well, as long as I don't accidentally click on a filenode. It then screws with my program and causes all kinds of exceptions to occur, because it's filling out the tree with directories and files according to node clicked. I need to filter out my filenodes when they're clicked, but I can't figure out how to determine if a node is a drvnode, dirnode, or filenode. I thought the key would do it, but that is an integer index. At present, I've switched to adding files into a listbox until I can come up with a solution. The problem with this, it makes it harder to get a path to the file via my treeview. Does anybody have any suggestions? I may leave the files in the listbox since there is no apparent way to select multiple nodes from a treeview; but I would still like to know how to tell the node type. |
|
|
|
|
|
#5 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Re: Filling out a treeview on a form
or is it just a node once it's added to the treeview? No different than all the other nodes with the exception of the settings it passes to the treeview?
|
|
|
|
|
|
#6 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Re: Filling out a treeview on a form
Thanks for the help, really.
|
|
|
|
|
|
#7 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
I have finished my project. Basically what it does is let you change the files on your computer in a number of ways. I call it a batch renamer for lack of a better term. It lets you rename file extensions on a list of files, or append a date in several formats, or even append a tag to a list of files. I would post the finished code/project if anybody was interested. I would also love to hear comments on how to make it more secure, or critiques on how I could have done it better.
|
|
|
|
|
|
#8 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Re: Filling out a treeview on a form
I don't know if this is the cold shoulder or what, but I'll assume it is.
|
|
|
|
|
|
#9 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Re: Filling out a treeview on a form
You could tweak it to use Icon.ExtractAssociatedIcon instead of a few generic images.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| FFT DWTIB -> Optimization -> Choosing An Appropriate Run Time | Sane | Software Design and Algorithms | 7 | Dec 1st, 2006 10:40 AM |
| Show or hiding forms/modifying control properties ..from different a form.. | cloud- | C# | 4 | Nov 10th, 2006 10:51 AM |
| Form Submit Blues | MegaArcon | Python | 3 | Dec 14th, 2005 4:20 PM |
| .NET Timer Form closing issue | MBirchmeier | C# | 4 | Nov 21st, 2005 10:00 AM |
| entering data into excel from a form | glevine | Perl | 1 | Nov 18th, 2005 5:03 PM |