Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Tree View and Folders directories

Tree View and Folders directories

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structureshelpquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FriendlySoluations
    wrote on last edited by
    #1

    Hi All I want ask you how can i use tree wiew in VB.NET to brows for folders in specific drive(c:\,d:\,.....) i want to view all files and i want to open them when them clicked (i want VB.NET code to implemnt this problem in other words my problem seem like Tree of folders in windows when we select folder all it's content are open beside it and we can select any file by click on it)

    A 1 Reply Last reply
    0
    • F FriendlySoluations

      Hi All I want ask you how can i use tree wiew in VB.NET to brows for folders in specific drive(c:\,d:\,.....) i want to view all files and i want to open them when them clicked (i want VB.NET code to implemnt this problem in other words my problem seem like Tree of folders in windows when we select folder all it's content are open beside it and we can select any file by click on it)

      A Offline
      A Offline
      alhokail
      wrote on last edited by
      #2

      i am not sure what you are looking for but you can use the OpenFileDialog found in VB.NET if this is not good for you and you want to implement something like windows explorer you have to write your own code to browse files and folders and add them to the tree view. hope this helps you

      F 1 Reply Last reply
      0
      • A alhokail

        i am not sure what you are looking for but you can use the OpenFileDialog found in VB.NET if this is not good for you and you want to implement something like windows explorer you have to write your own code to browse files and folders and add them to the tree view. hope this helps you

        F Offline
        F Offline
        FriendlySoluations
        wrote on last edited by
        #3

        Thank You Sir I need to know how to implement something like windows explorer (My problems looks like when we open My Computer and then click on the icon Folders we see tree on the left of the screen and on the right we see all files and folder in specific directory I need to implement this) I look forward to hear from you soon

        A 1 Reply Last reply
        0
        • F FriendlySoluations

          Thank You Sir I need to know how to implement something like windows explorer (My problems looks like when we open My Computer and then click on the icon Folders we see tree on the left of the screen and on the right we see all files and folder in specific directory I need to implement this) I look forward to hear from you soon

          A Offline
          A Offline
          alhokail
          wrote on last edited by
          #4

          Dim Files() As String = System.IO.Directory.GetFiles("c:\") Dim Folders() As String = System.IO.Directory.GetDirectories("C:\") For Each F As String In Folders If (System.IO.File.GetAttributes(F) And IO.FileAttributes.Hidden) <> IO.FileAttributes.Hidden Then Me.TreeView1.Nodes.Add(F, F.Split("\")(F.Split("\").Length - 1)) End If Next For Each F As String In Files If (System.IO.File.GetAttributes(F) And IO.FileAttributes.Hidden) <> IO.FileAttributes.Hidden Then Me.TreeView1.Nodes.Add(F, F.Split("\")(F.Split("\").Length - 1)) End If Next you can use something simillar to this code. this code only adds files and folders under the c:\ directory. you can extend this code to add other files under each folder. the best way is to make the function a recursive function but this will make your program very very slow. what i suggest is call this function everytime a node is clicked this add the childern of that node using this function. the nodes.add function can be extended to include icons to differ between a file and a folder. to add a child node you can use the following line: me.TreeView1.Nodes.Item(me.TreeView1.Nodes.IndexOfKey(Key)).Nodes.Add() where the key is what i specified in the first argument of the Nodes.add line (= F) hope this helps, if you need further help please let me know Khalid

          F 1 Reply Last reply
          0
          • A alhokail

            Dim Files() As String = System.IO.Directory.GetFiles("c:\") Dim Folders() As String = System.IO.Directory.GetDirectories("C:\") For Each F As String In Folders If (System.IO.File.GetAttributes(F) And IO.FileAttributes.Hidden) <> IO.FileAttributes.Hidden Then Me.TreeView1.Nodes.Add(F, F.Split("\")(F.Split("\").Length - 1)) End If Next For Each F As String In Files If (System.IO.File.GetAttributes(F) And IO.FileAttributes.Hidden) <> IO.FileAttributes.Hidden Then Me.TreeView1.Nodes.Add(F, F.Split("\")(F.Split("\").Length - 1)) End If Next you can use something simillar to this code. this code only adds files and folders under the c:\ directory. you can extend this code to add other files under each folder. the best way is to make the function a recursive function but this will make your program very very slow. what i suggest is call this function everytime a node is clicked this add the childern of that node using this function. the nodes.add function can be extended to include icons to differ between a file and a folder. to add a child node you can use the following line: me.TreeView1.Nodes.Item(me.TreeView1.Nodes.IndexOfKey(Key)).Nodes.Add() where the key is what i specified in the first argument of the Nodes.add line (= F) hope this helps, if you need further help please let me know Khalid

            F Offline
            F Offline
            FriendlySoluations
            wrote on last edited by
            #5

            Dear Sir I thank you very much I know how to fill tree and I use the following Dim aDriveAs String For Each aDrive In Directory.GetDirectories("E:\") If (File.GetAttributes(aDrive) And IO.FileAttributes.Hidden) <> IO.FileAttributes.Hidden Then T.Nodes(0).Nodes.Add(aDrive) End If Next But I need the following When I select folder from tree I want to display All files and Folders on a panel or somthing like this,i.e. in the same way as (windows explorer) so I can Open,Copy or delete any file or folder Thank you again

            A 1 Reply Last reply
            0
            • F FriendlySoluations

              Dear Sir I thank you very much I know how to fill tree and I use the following Dim aDriveAs String For Each aDrive In Directory.GetDirectories("E:\") If (File.GetAttributes(aDrive) And IO.FileAttributes.Hidden) <> IO.FileAttributes.Hidden Then T.Nodes(0).Nodes.Add(aDrive) End If Next But I need the following When I select folder from tree I want to display All files and Folders on a panel or somthing like this,i.e. in the same way as (windows explorer) so I can Open,Copy or delete any file or folder Thank you again

              A Offline
              A Offline
              alhokail
              wrote on last edited by
              #6

              i am not sure if i understod you correctly but you can use the AfterSelect event of the treeview control and you can get the name of the node by using the following line MsgBox(e.Node.Text) but for your code, it will be harder to read because you are including the entire path of each file which makes it hard for the user. What i suggest is use the same code as mine (add only the name of the file and use the Name property of the node to store the whole path. if you do this, then you would have to use the line: MsgBox(e.Node.Name) instead of the first one. after you get the path of the selected node, then you can use a list view control to display files and folders and do whatever you want to do with them. hope this makes things more clear. Khalid

              F 1 Reply Last reply
              0
              • A alhokail

                i am not sure if i understod you correctly but you can use the AfterSelect event of the treeview control and you can get the name of the node by using the following line MsgBox(e.Node.Text) but for your code, it will be harder to read because you are including the entire path of each file which makes it hard for the user. What i suggest is use the same code as mine (add only the name of the file and use the Name property of the node to store the whole path. if you do this, then you would have to use the line: MsgBox(e.Node.Name) instead of the first one. after you get the path of the selected node, then you can use a list view control to display files and folders and do whatever you want to do with them. hope this makes things more clear. Khalid

                F Offline
                F Offline
                FriendlySoluations
                wrote on last edited by
                #7

                Dear Sir Ithank You and I am Very Sory But Now my problem is can I use a list view control to display files and folders and do whatever you want to do with them. I need to know how can I display files and folders as larg icons

                A 1 Reply Last reply
                0
                • F FriendlySoluations

                  Dear Sir Ithank You and I am Very Sory But Now my problem is can I use a list view control to display files and folders and do whatever you want to do with them. I need to know how can I display files and folders as larg icons

                  A Offline
                  A Offline
                  alhokail
                  wrote on last edited by
                  #8

                  to add items you just need to call ListView1.Items.Add("aa" ,0) to add an item called "aa" with icon index of 0 the index of the icons is found from an ImageList control that you have to add and insert images into. after adding the ImageList, you have to specify the Me.ListView1.LargeImageList = Me.ImageList1 to define the large images of the items and then change the image size in the ImageList to 32,32. by default, the ListView control displays LargeIcons (after setting up the steps before) but just in case you have to specify the propoprty ListView1.View = View.LargeIcon hope this helps you.. Khalid

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups