Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 13th, 2007, 3:35 AM   #1
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 245
Rep Power: 1 Jabo is on a distinguished road
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
...it runs filling up the treeview until it says directory not found. The path it lists is about 10 directories deep, but the last part is \My Computer. This is perplexing me to no end, and I am having trouble finding detailed information on using the treeview object. Can anybody help? I'm sure there's a better way because it seems it's not just getting the 1st level directories but all directories, at least on that drive.
Jabo is offline   Reply With Quote
Old Oct 13th, 2007, 4:34 AM   #2
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 245
Rep Power: 1 Jabo is on a distinguished road
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
Jabo is offline   Reply With Quote
Old Oct 13th, 2007, 9:40 PM   #3
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 245
Rep Power: 1 Jabo is on a distinguished road
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 = 2

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.
Jabo is offline   Reply With Quote
Old Oct 20th, 2007, 2:26 PM   #4
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 245
Rep Power: 1 Jabo is on a distinguished road
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.
Jabo is offline   Reply With Quote
Old Oct 20th, 2007, 6:38 PM   #5
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 245
Rep Power: 1 Jabo is on a distinguished road
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?
Jabo is offline   Reply With Quote
Old Oct 21st, 2007, 1:52 AM   #6
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 245
Rep Power: 1 Jabo is on a distinguished road
Re: Filling out a treeview on a form

Thanks for the help, really.
Jabo is offline   Reply With Quote
Old Oct 26th, 2007, 10:17 PM   #7
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 245
Rep Power: 1 Jabo is on a distinguished road
Thumbs up 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.
Jabo is offline   Reply With Quote
Old Nov 1st, 2007, 11:12 PM   #8
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 245
Rep Power: 1 Jabo is on a distinguished road
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.
Jabo is offline   Reply With Quote
Old Nov 1st, 2007, 11:28 PM   #9
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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
Dameon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC