![]() |
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() |
I think I have it figured out now. Made the following changes:
:
For Each drv As Object In My.Computer.FileSystem.Drives() |
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()The 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. |
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. |
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?
|
Re: Filling out a treeview on a form
Thanks for the help, really.
|
Re: Filling out a treeview on a form
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.
|
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.
|
Re: Filling out a treeview on a form
You could tweak it to use Icon.ExtractAssociatedIcon instead of a few generic images.
|
| All times are GMT -5. The time now is 3:32 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC