473,405 Members | 2,171 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,405 software developers and data experts.

why doesn't treeview provide application-defined sort?

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 respectively. If setting its Sorted true,
all nodes will be sorted. It's not my requirement.

Any idea.

alan
Nov 16 '05 #1
3 5504
Alan,

Have you tried the TreeViewNodeSorter property? It will allow you to
set an IComparer implementation used for the sort.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alan" <li***@channel.com> wrote in message
news:uu*************@TK2MSFTNGP10.phx.gbl...
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 respectively. If setting its Sorted true,
all nodes will be sorted. It's not my requirement.

Any idea.

alan

Nov 16 '05 #2
But which class has the TreeViewNodeSorter property? I don't find it. BTW, I
use the .Net FCL 1.1.

Thanks.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> дÈëÏûÏ¢
ÐÂÎÅ:#J*************@TK2MSFTNGP10.phx.gbl...
Alan,

Have you tried the TreeViewNodeSorter property? It will allow you to
set an IComparer implementation used for the sort.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alan" <li***@channel.com> wrote in message
news:uu*************@TK2MSFTNGP10.phx.gbl...
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 respectively. If setting its Sorted true, all nodes will be sorted. It's not my requirement.

Any idea.

alan


Nov 16 '05 #3
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
ArrayList.

e.g. in a sub-class of TreeView:

public void Sort(IComparer comparer) {

ArrayList list = new ArrayList(this.Nodes.Count);
foreach (TreeNode childNode in this.Nodes) {
list.Add(childNode);
}
list.Sort(comparer);

this.BeginUpdate();
this.Nodes.Clear();
foreach (TreeNode childNode in list) {
this.Nodes.Add(childNode);
}
this.EndUpdate();
}

Obviously, this can be adapted to deal with the child-nodes of
individual nodes. Just pass a node to the method above, and replace
this.Nodes with node.Nodes.

You can also do it with API calls, but it's messy and as far as I can
tell, it's not much quicker. If you want to know this way, let me
know.

Chris.

"Alan" <li***@channel.com> wrote in message news:<#R*************@TK2MSFTNGP10.phx.gbl>...
But which class has the TreeViewNodeSorter property? I don't find it. BTW, I
use the .Net FCL 1.1.

Thanks.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> дÈëÏûÏ¢
ÐÂÎÅ:#J*************@TK2MSFTNGP10.phx.gbl...
Alan,

Have you tried the TreeViewNodeSorter property? It will allow you to
set an IComparer implementation used for the sort.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alan" <li***@channel.com> wrote in message
news:uu*************@TK2MSFTNGP10.phx.gbl...
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 respectively. If setting its Sorted true, all nodes will be sorted. It's not my requirement.

Any idea.

alan


Nov 16 '05 #4

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

Similar topics

0
by: Plumer | last post by:
Hello everyone, I am using MS .NET Framework 1.0 Version 1.0.3705 developing a C# client application using SQL Server on the server side. I am looking to implement drag & drop in a TreeView...
4
by: meh | last post by:
I need to be able to persist a treeView to disk. I would like to save the node text, tag, image and selected image. I have done this using vb but I cant seem to translate from vb to vc#. Can ne1...
0
by: meh | last post by:
Still have not been able to convert this. More importently.....Is this sample going about it the right way??? tia meh Here is the vb code.........I keep looking at older vb.net projects to...
3
by: lwhitb1 | last post by:
I created my own icons, and I would like to be able to use them instead of all the default icons they provide. Is this possible? -- lee
3
by: Jan Wrage | last post by:
Hi! I would like to implement a treeview in my existing application. It should show my entire Active-Directory structure, i.e. all Groups, Containers and OUs. Could somebody help me with...
1
by: musosdev | last post by:
Hi guys I was using the Microsoft.Web.UI.WebControls extra namespace in my application to provide me with a TreeView control. I was using specifically ..GetNodeFromIndex(), SelectedNodeIndex and...
6
by: Christof Nordiek | last post by:
Hi all, in my WinForm-Application i have a strange problem with the TreeView Control. As you can see in the samplecode below, i fill the TreeView by adding some nodes with sub nodes. (The...
18
by: =?Utf-8?B?TGkgV2VuZw==?= | last post by:
Hi, Is there a way for TreeView to have multiple selections? But I am not talking about its checked boxes. I want a way similar to ListView with MultiSelect = True. So I can use or key and...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
3
by: dutsnekcirf | last post by:
I have a treeview control on a custom task pane in Excel. I've enable the ability to use Drag & Drop (by following this how-to) on the treeview to change the order of the nodes. The problem though...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.