473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

sort treeview

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

Feb 9 '06 #1
4 5151
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
"Sam" <sa*************@googlemail.com> escribió en el mensaje
news:11**********************@f14g2000cwb.googlegr oups.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

Feb 9 '06 #2
Sam
Thanks for your answer Carlos.

Feb 9 '06 #3
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/

Feb 9 '06 #4
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()

Feb 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ed Sutton | last post by:
I need to do a custom sort on a TreeView. I have various object types associated with the TreeNode Tag property. I want to sort objects of the same type at the top of the list, other objects at...
3
by: Alan | last post by:
Hi all, Besides the Sorted property, the TreeView control in .Net FCL doesn't provide application-defined sort. But I put several kinds of data into the treeview, and hope to sort them...
0
by: Chris Bowring | last post by:
Alan, the easiest way to sort a TreeView is to: * add the nodes to an ArrayList * sort the ArrayList with an IComparer * remove the nodes from the TreeView and add them back from the...
6
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview....
14
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
2
by: Patrick | last post by:
I got a page that loads a xml file into a treeview control. I want it to sort the data before sending it to the treeview control is that possible? <root> <level1 name="" src="" order="0">...
1
by: csharp | last post by:
I am generating an xml file off an employees table from a database to use to databind a treeview to on a master page rather than call the db every time the page loads. I need to take this XML...
1
by: (PeteCresswell) | last post by:
I'm loading a TreeView control from a recordset that's sequenced by a date. When I step through the code, I *think* I'm seeing the nodes created in the expected sequence. Problem is, when the...
1
by: Red Baron | last post by:
Hi all, Is there a any built-in method in TreeVew for sorting the nodes. I mean, there is a Sort() method in windows form version of treeview but i can not find any method in asp.net version,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.