Results 1 to 3 of 3

Thread: How to automaticly add nodes to the treeview?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    32

    How to automaticly add nodes to the treeview?

    Hi, I was wondering, how do you automaticly add items to the treeview when you start the program?

    When it starts, I want it to look for a certain type of file in a certain folder that the user selects, and for each file add a new node to the Treeview.


    Please help....


    Josh
    Smartbar XP is WAY better then Dashboard. http://www.smartbarxp.com

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    32
    anybody? please help, its important!

    Josh
    Smartbar XP is WAY better then Dashboard. http://www.smartbarxp.com

  3. #3
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Something like this?

    VB Code:
    1. Private Sub RefreshList()
    2.         Dim Imageindex As Short = 0
    3.         Try
    4.             Dim topics() As String = Directory.GetDirectories("[i]<your start directory>[/i]")
    5.  
    6.             Dim str As String
    7.  
    8.             For Each str In topics
    9.                 'Dim Imageindex As Short
    10.                 Dim dir As New DirectoryInfo(str)
    11.                 Dim fi() As FileInfo = dir.GetFiles("*.rtf")
    12.  
    13.                 Dim node As New TreeNode(str.Substring(str.IndexOf("\") + 1), Imageindex, Imageindex)
    14.                 TreeView1.Nodes.Add(node)
    15.  
    16.                 Dim f As FileInfo
    17.  
    18.                 For Each f In fi
    19.                     node.Nodes.Add(f.Name.Remove(f.Name.IndexOf("."), 4))
    20.                 Next
    21.                 Imageindex += 1
    22.             Next
    23.         Catch ex As Exception
    24.             MessageBox.Show(ex.Message)
    25.         End Try
    26.  
    27.     End Sub

    just call RefreshList() to create the Treeview.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width