Home All Groups Group Topic Archive Search About
Author
9 Feb 2006 10:04 AM
Sam
Hi,
How can I sort the root nodes of a treeview according to a integer
stored in their tag property? I want to do that at run time on a
button's click event.

Thank you

Author
9 Feb 2006 10:28 AM
Carlos J. Quintero [VB MVP]
AFAIK, the Sorted property of the Treeview only sorts alphabetically, so you
will have to set it to false and sort the treenodes in an array (Array.Sort)
before adding them to the treeview, providing an IComparer that uses the Tag
property of the treenodes.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com


Show quoteHide quote
"Sam" <samuelberthe***@googlemail.com> escribió en el mensaje
news:1139479484.119403.218240@f14g2000cwb.googlegroups.com...
> Hi,
> How can I sort the root nodes of a treeview according to a integer
> stored in their tag property? I want to do that at run time on a
> button's click event.
>
> Thank you
>
Author
9 Feb 2006 11:02 AM
Sam
Thanks for your answer Carlos.
Author
9 Feb 2006 1:25 PM
tommaso.gastaldi
A quick and dirty way, to avoid reload, could also be to use the sort
feature and to make the labels start with *formatted* numbers (if
acceptable) ...

-tom

Datatime Prj
http://cam70.sta.uniroma1.it/TechnicalPreview/
Author
10 Feb 2006 12:27 PM
Sam
I've used the following to do it: ;-)

Public Class NodesList
        Inherits List(Of TreeNode)

        Public Overloads Sub Sort()
            MyBase.Sort(New NodeTagComparer())
        End Sub
    End Class

    Public Class NodeTagComparer
        Implements IComparer(Of TreeNode)

        Public Function Compare(ByVal node1 As TreeNode, ByVal node2 As
TreeNode) As Integer Implements IComparer(Of TreeNode).Compare
            Return (DirectCast(node1.Tag,
Query).SortOrder.CompareTo(DirectCast(node2.Tag, Query).SortOrder))
        End Function
    End Class

  Dim lstNodes As New AdminSystemLib.NodesList
        For Each n As TreeNode In Me.Nodes
            lstNodes.Add(n)
        Next
        lstNodes.Sort()