Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TreeView
Message
De
05/07/2005 11:51:52
 
 
À
05/07/2005 10:46:20
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
Divers
Thread ID:
01029000
Message ID:
01029025
Vues:
12
Paul,

I tried your code, minus the stuff with the icons (I didn't want to take the time to mess with putting Icon images in my test) ... it worked pretty fast, as near as I could tell. I'm wondering if all the stuff you're doing with the icons is what's causing it to be slow. Just to test this out, try commenting out all your code that does stuff with the icons and see if it speeds things up. If it does, you may have to re-think the way you're processing the icons.

~~Bonnie




>I am working on a class using the treeview control to display files and folders similar to windows explorer except with check boxes to allow a user to select individual files which are then stored in an array list.
>
>Everything works ok except it is very slow to display a folder with lots of files in it. I am populating the nodes on the onbeforeexpand event to avoid having to loop throughought the entire files system. I will post the relevent code below and hopefully somebody will see something.
>
>
>    Protected Overrides Sub OnBeforeExpand(ByVal e As System.Windows.Forms.TreeViewCancelEventArgs)
>        'MyBase.OnBeforeExpand(e)
>        If e.Node.ImageIndex = IconIndex.FolderClosed Then
>            e.Node.ImageIndex = IconIndex.FolderOpen
>            e.Node.SelectedImageIndex = IconIndex.FolderOpen
>        End If
>        MyBase.SelectedNode = e.Node
>        If e.Node.Tag = "" Then
>            'do nothing
>        ElseIf e.Node.Nodes(0).Text = DUMMY_NODE Then
>            'load folders
>            e.Node.Nodes.Clear()
>            Try
>                'get the full path
>                Dim fpath As String = e.Node.Tag
>                'check for '\' at the end
>                If Mid(fpath, Len(fpath) - 1, 1) <> "\" Then
>                    fpath += "\"
>                End If
>                'get the sub directories
>                Dim fls() As String = IO.Directory.GetDirectories(fpath)
>                'create an enumerator
>                Dim en As IEnumerator = fls.GetEnumerator
>                Cursor = Cursors.WaitCursor
>                'move through enumerator
>                While en.MoveNext
>                    'add the folder to the treeview
>                    Dim n As CustomTreeNode = New CustomTreeNode(Replace(Mid(en.Current, Len(fpath) + 1), "\", ""), 0, 0)
>                    n.Tag = en.Current
>                    n.isfolder = True
>                    e.Node.Nodes.Add(n)
>                    'add a 'dummy' node so it can be expanded
>                    n.Nodes.Add(DUMMY_NODE)
>                    ' Application.DoEvents()
>                End While
>                'set the folder to closed
>                If e.Node.Nodes.Count = 0 Then
>                    e.Node.ImageIndex = IconIndex.FolderClosed
>                    e.Node.SelectedImageIndex = IconIndex.FolderClosed
>                End If
>                'should we show the files?
>
>                ' Used subclassed treenode to store File Property as True
>
>                If _showfiles Then
>
>                    'get the files based on the search pattern
>                    Dim files() As String = IO.Directory.GetFiles(fpath, _spattern)
>                    Dim enf As IEnumerator = files.GetEnumerator
>                    'move through enumerator
>
>                    While enf.MoveNext
>                        'get the default Icon
>
>                        Dim di As DefaultIcon = New DefaultIcon
>                        di.DefaultIcon = "default.ico"
>                        'trim off any '\'
>                        Dim fname As String = Replace(Mid(enf.Current, Len(fpath) + 1), "\", "")
>                        Dim ico As Drawing.Icon = di.GetIcon(Mid(fname, InStr(fname, ".") + 1))
>                        Dim Icons As IList = ilImages.Images
>                        Dim index As Integer
>                        Dim i As Integer
>                        'check if ico exists in Icons, if it does use that, if not add ico
>                        For i = 0 To Icons.Count - 1
>                            If Icons(i).Equals(ico) Then
>                                index = i
>                            End If
>                        Next
>                        If i = Icons.Count Then
>                            'didnt find icon, add it
>                            ilImages.Images.Add(ico)
>                        End If
>                        'add the file to the treeview with the ico
>
>                        Dim fn As CustomTreeNode = New CustomTreeNode(fname, i, i)
>                        fn.FileName = enf.Current
>
>                        fn.isfolder = False
>                        e.Node.Nodes.Add(fn)
>                        Application.DoEvents()
>
>                    End While
>
>                End If
>
>            Catch ex As Exception
>                MsgBox(ex.Message)
>                'if there is an exception clear the node
>                e.Node.Nodes.Clear()
>                If e.Node.ImageIndex = IconIndex.FolderOpen Then
>                    e.Node.ImageIndex = IconIndex.FolderClosed
>                    e.Node.SelectedImageIndex = IconIndex.FolderClosed
>                End If
>                'If e.Node.ImageIndex = IconIndex.CDRom Or IconIndex.FixedDrive Or IconIndex.Floppy Or IconIndex.RamDisk Or IconIndex.Remote Or IconIndex.Removable Then
>                'e.Node.ImageIndex = IconIndex.ErrorDisk
>                'e.Node.SelectedImageIndex = IconIndex.ErrorDisk
>                'End If
>            Finally
>                Cursor = Cursors.Default
>            End Try
>        End If
>    End Sub
>
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform