Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42220

VS 2010 Treeview Sort and Group Nodes

$
0
0
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

Viewing all articles
Browse latest Browse all 42220

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>