Results 1 to 3 of 3

Thread: Treeview Sort and Group Nodes

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    4

    Treeview Sort and Group Nodes

    Hello All,

    I have Extended treeview, in order to have Multiselect.
    I also have Extended three different types of nodes Group, Project and ProjectDirectory from Treenode.

    The Hirarchy is like Bellow

    +Group1
    + ProjectNodeA
    -ProjectDirectory Node 1
    Group2
    + ProjectNodeB
    -ProjectDirectory Node 1


    I want to Sort the Group and ProjectNodes and then Display the GroupNodes first and then Project Nodes

    Current solution i have is
    Code:
    Private Sub SortNodes()
            Dim pnodes As New List(Of KurmaahTreeNode)
            Dim gnodes As New List(Of KurmaahTreeNode)
    
            For Each nnode As KurmaahTreeNode In Me.TreeView.Nodes
                If nnode.NodeType = TypeOfNode.GroupNode Then
                    gnodes.Add(nnode.Clone())
                ElseIf nnode.NodeType = TypeOfNode.ProjectNode Then
                    pnodes.Add(nnode.Clone())
                End If
            Next
    
            Dim tempparray() As KurmaahTreeNode = Nothing
            Dim tempgarray() As KurmaahTreeNode = Nothing
    
            Array.Resize(tempparray, pnodes.Count)
            Array.Resize(tempgarray, gnodes.Count)
    
            tempparray = pnodes.ToArray()
            tempgarray = gnodes.ToArray()
    
            Try
                Array.Sort(tempparray, New TreeNodeComparer)
                Array.Sort(tempgarray, New TreeNodeComparer)
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try
            
    
            Me.TreeView.Nodes.Clear()
    
            Me.TreeView.Nodes.AddRange(tempgarray)
            Me.TreeView.Nodes.AddRange(tempparray)
        End Sub
    But the problem is that when i try to Call the function from AfterLabelEdit, weird behavior is observed

    Is there a better way to do this ??
    Can anyone guide me on this thanks

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: Treeview Sort and Group Nodes

    what exactly is happening?

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    4

    Re: Treeview Sort and Group Nodes

    The Sort method runs infinitly and then ERROR pops up
    Context 0x4aa77a0' is disconnected. Releasing the interfaces from the current context (context 0x4aa7630).This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the applicationis completely done with the RuntimeCallableWrappers that represent COM components that liveinside them.

Tags for this Thread

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