By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

TreeView: Sort Dynamically?

P: n/a
Are there TreeViews that can be sorted on-the-fly? i.e. that can be sorted
without reloading them?
--
PeteCresswell
Aug 31 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You need to store all the node names in an Array or a table. I think
the table would be easier.

First clear all the nodes - or only clear the desired nodes.

Me.Treeview0.Nodes.Clear

Then re-add the nodes from the table in the order that you want. By
storing the Node names in a table you can use sql to sort the nodes.

Dim RS As DAO.Recordset
Set RS = CurrentDB.OpenRecordset("Select Keys, Relatives, NodeText From
tblNodes Order By Nodes DESC")

You can sort subsets this way too. You clear only subnodes under a main
node, then re-add the subnodes to the main node. This will only work
with a properly normalized table. You have to associate each childnode
with a ParentNode in the table. It is hierarchical.

Main1, submain1, sub1
Main1, submain1, sub2
Main1, submain1, sub3
Main1, submain2, sub1
Main1, submain2, sub2
Main1, submain2, sub3
Main2, submain1, sub1
Main2, submain1, sub2
Main2, submain1, sub3
...

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 31 '06 #2

P: n/a

http://www.vbaccelerator.com/home/VB...ol/article.asp

or
http://tinyurl.com/p5jrv
I've just tested it and it works fine in Access.

It has a Movenode method which alows you to (strangely enough) move nodes
around.

This is the first time I've tried it so the codes probably a bit rough but
the following:-

Private Sub Command1_Click()
Dim tvw As vbalTreeView
Dim nodTop As cTreeViewNode
Dim nodSub As cTreeViewNode
Dim nodSubSub As cTreeViewNode
Dim children As cTreeViewNodes
Dim subChildren As cTreeViewNodes

Set tvw = Me.vbalTreeView0.Object

Set nodTop = tvw.Nodes.Add(, etvwFirst, "xxx")
nodTop.Text = "1111"

Set children = nodTop.children

Set nodSub = children.Add(, etvwChild, "yyyy")
nodSub.Text = "2222"

Set subChildren = nodSub.children

Set nodSubSub = subChildren.Add(, etvwChild, "zzzz")
nodSubSub.Text = "3333"

End Sub

Added three nodes in the following configuration

1111
|____ 2222
|____ 3333

Then the following code

Private Sub Command2_Click()
Dim tvw As vbalTreeView
Dim nodTop As cTreeViewNode
Dim nodSub As cTreeViewNode
Dim nodSubSub As cTreeViewNode
Dim children As cTreeViewNodes
Dim subChildren As cTreeViewNodes

Set tvw = Me.vbalTreeView0.Object

Set nodTop = tvw.Nodes("xxx")
Set children = nodTop.children

Set nodSub = children.Item("yyyy")
Set subChildren = nodSub.children

Set nodSubSub = subChildren.Item("zzzz")

Call nodSubSub.MoveNode(nodTop, etvwChild)
End Sub

Moved node 3333 to the folowing configuration

1111
|____ 2222
|____ 3333

--

Terry Kreft
"(PeteCresswell)" <x@y.Invalidwrote in message
news:oc********************************@4ax.com...
Are there TreeViews that can be sorted on-the-fly? i.e. that can be
sorted
without reloading them?
--
PeteCresswell

Aug 31 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.