HOW TO: Treeview, obtain the first node index in a sorted Treeview

G

Guest

Hi TWIMC

I have a treeview that is populated by an query that is sorted so that
parents are added before their associated siblings, thus my source data is
not alphabetically sorted like the treeview appears on the form. Hence is I
use the statement bjTree.Nodes(1).EnsureVisible it doesn't show the viewable
first node in the treeview it shows the node that was added to the treeview
first.

So can anyone tell me what the correct syntax is to ascertain the Index
value of the first 'visible' nodes is, thanks.

I expect it to be simple but I think is one of those, 'Can't see the wood
for the trees'

TIA

KM
 
G

Guest

Kevin,

Try bjTree.Nodes(1).Root.FirstSibling.EnsureVisible

That should get you there regardless of where bjTree.Nodes(1) is

Regards

swas
 
G

Guest

No that won't work, bjTree.Nodes(1) would be the first item to be added to
the tree and if it the text started with a Z it would appear at the bottom.

What i need is bjTree.Nodes(X), where X is the first item in the tree once
it has been sorted.

Thanks anyway for trying, just hope someone else might have the write answer
and does think this questions is now correctly answered and therefore closed,
so I may have to post the same question again.
 
G

Guest

Ended up cheating by using a query to return the first ancestor and then look
for it in the treeview to return its index.

varRETURN = "a" & Format(DLookup("[UC_CODE]",
"[qselCLIENT_HIERARCHY_FIRST]"), "000000000000")
For Each nodCurrent In objTree.Nodes
If nodCurrent.Key = varRETURN Then
NodeIndex = nodCurrent.Index
Exit For
End If
Next

objTree.Nodes(NodeIndex).EnsureVisible
 
G

Guest

Kevin,

You should also be able to use the keyvalue in the Nodes() collection. It
looks like you are using "a" & [UC_Code] to denote the key value, so if you
have a query that identify's the root nodes, you should be able to sort that
query alphabetically and determine the [UC_Code] associated with that first
node (I think your varReturn does that). I tried the following from the
debug window in one of my applications, and it expanded the tree to make the
appropriate node ("a123") visible.

me.tvw_Tree.object.nodes("a123").EnsureVisible

HTH
Dale
--
Email address is not valid.
Please reply to newsgroup only.


Kevin McCartney said:
Ended up cheating by using a query to return the first ancestor and then look
for it in the treeview to return its index.

varRETURN = "a" & Format(DLookup("[UC_CODE]",
"[qselCLIENT_HIERARCHY_FIRST]"), "000000000000")
For Each nodCurrent In objTree.Nodes
If nodCurrent.Key = varRETURN Then
NodeIndex = nodCurrent.Index
Exit For
End If
Next

objTree.Nodes(NodeIndex).EnsureVisible

Kevin McCartney said:
No that won't work, bjTree.Nodes(1) would be the first item to be added to
the tree and if it the text started with a Z it would appear at the bottom.

What i need is bjTree.Nodes(X), where X is the first item in the tree once
it has been sorted.

Thanks anyway for trying, just hope someone else might have the write answer
and does think this questions is now correctly answered and therefore closed,
so I may have to post the same question again.
 
G

Guest

Kevin,

It shouldn't matter if the node starts with Z or located at the start,
middle or end. The root node is the highest point in the branch heirachy, and
the firstsibling of this must be the top root node, which is what you are
looking for.

bjTree.Nodes(1) is just an arbitary starting point that should be a valid
node. It could be any index value, so long as it is a valid node.

swas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top