treeview & listview, slow directory listing 
Author Message
 treeview & listview, slow directory listing

im using code from "Mastering Visual Basic .NET" to use treeview and
listview to browse a specific folder on my network. its going to do more
file related operations, but im starting with the basics first.

its EXTREMELY slow building the nodes. does anyone know of another way of
doing this?

ill post the code below.

thanks for helping a newbie!

Matt

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _

        ByVal e As System.Windows.Forms.TreeViewEventArgs) _

        Handles TreeView1.AfterSelect

        Dim Nd As TreeNode

        Dim pathName As String

        Nd = TreeView1.SelectedNode

        pathName = Nd.Text

        ShowFiles(pathName)

End Sub

Public Function ExtractFileName(ByVal PathFileName As String) As String

        Dim delimiterPosition As Integer

        delimiterPosition = PathFileName.LastIndexOf("\")

    If delimiterPosition > 0 Then

        Return PathFileName.Substring(delimiterPosition + 1)

        Else

        Return PathFileName

    End If

End Function

Public Function ExtractPathName(ByVal PathFileName As String) As String

        Dim delimiterPosition As Integer

        delimiterPosition = PathFileName.LastIndexOf("\")

    If delimiterPosition > 0 Then

        Return PathFileName.Substring(0, delimiterPosition)

        Else

        Return ""

    End If

End Function

Sub ScanFolder(ByVal folderSpec As String, ByRef currentNode As TreeNode)

        Dim thisFolder As String

        Dim allFolders() As String

        allFolders = Directory.GetDirectories(folderSpec)

        For Each thisFolder In allFolders

        Dim Nd As TreeNode

        Nd = New TreeNode(thisFolder)

        currentNode.Nodes.Add(Nd)

        folderSpec = thisFolder

        ScanFolder(folderSpec, Nd)

        Next

End Sub

Sub ShowFiles(ByVal selFolder As String)

        ListView1.Items.Clear()

        Dim files() As String

        Dim file As String

        files = Directory.GetFiles(selFolder)

        For Each file In files

        Dim LItem As New ListViewItem()

        LItem.Text = ExtractFileName(file)

        Dim FI As New FileInfo(file)

        LItem.SubItems.Add(FI.Length.ToString("#,###"))

        LItem.SubItems.Add(FormatDateTime(Directory.GetCreationTime(file), _

        DateFormat.ShortDate))

        LItem.SubItems.Add(FormatDateTime(Directory.GetLastAccessTime(file),
_

        DateFormat.ShortDate))

        ListView1.Items.Add(LItem)

    Next

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        Dim Nd As New TreeNode()

        Nd = TreeView1.Nodes.Add("g:\dwgs")

        ScanFolder("g:\dwgs", Nd)

End Sub



Sat, 09 Jul 2005 20:29:51 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Using treeview and listview controls to show directory/file structures

2. How to list directories in a TreeView control?

3. Treeview Directory listings

4. TreeView Directory Listing

5. Treeview - Drive/directory listing

6. How to add treeview nodes based on a directory list box

7. Treeview & Listview

8. Listview control & Treeview

9. TreeView + ListView +Drag&Drop

10. Force Treeviews & ListViews to LabelEdit

11. handling treeview & listview controls

12. TreeView & ListView

 

 
Powered by phpBB® Forum Software