|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
sort treeviewHi,
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 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. -- Show quoteHide quoteBest regards, Carlos J. Quintero MZ-Tools: Productivity add-ins for Visual Studio You can code, design and document much faster: http://www.mztools.com "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 > 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/ 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() |
|||||||||||||||||||||||