Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview sort

Status
Not open for further replies.

shaunhubbs

Technical User
Jun 6, 2005
57
CA
Hi all,

Am I under the correct impression that when setting the .sort property on a treeview to true that it is sorted alphabetically? The problem I am running into is that it seems to only sort alphabetically on the root set of nodes. In my application the root is always a SET of instruments and below the SET as children are the items (instruments, etc.).

Here is an example:

Set name #1
-- Item 7543525
-- Item 7543530
-- Item 7543540
-- Item 7543545
-- Item 7543550
-- Item 7543535 <-- I added this last node after the other ones, but it does not sort to its proper position which should be the third child in the list.

(NOTE: I did try a resort by turning the .sort property for the treeview to false and then true and also tried reloading the form to make sure it was not one of those simple things.)

I thought I had read somewhere that when the nodes are numeric it only sorts the first digit, but I added the number "6543535" underneath and that only sorted to the bottom as well.

On the root node, however, I did add a set name that should come before the current ones in the list and it sorted to the top where it should. Same for a set name that should come after; it was sorted to the bottom. (???)

Any ideas on how VB handles this treeview sort that might help out? Know a good way to write a function that could reindex the children nodes if they are, in fact, sorted by index if they are not on the root?

Thanks.

- Shaun
 
Here's what MSDN has to say about sorting a TreeView:

The Sorted property can be used in two ways: first, to sort the Node objects at the root (top) level of a TreeView control and, second, to sort the immediate children of any individual Node object. For example, the following code sorts the root nodes of a TreeView control:

Private Sub Command1_Click()
TreeView1.Sorted = True ' Top level Node objects are sorted.
End Sub

The next example shows how to set the Sorted property for a Node object as it is created:

Private Sub Form_Load()
Dim nodX As Node
Set nodX = TreeView1.Nodes.Add(,,,"Parent Node")
nodX.Sorted = True
End Sub

Setting the Sorted property to True sorts the current Nodes collection only. When you add new Node objects to a TreeView control, you must set the Sorted property to True again to sort the added Node objects.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top