As regards to my prior message, I have solved issue number 3, how to quickly
iterate
the whole tree-structure. Still, my other questions remain open.
But for what it is worth, and to all who might benefit from a quick way of
running
through all the possible items on a tree, here I am pasting in the sub routine,
that
will do the whole iteration. It is not more than a few lines of coding, and will
do with any number of branches and leaves, from what I can see. In the pasted
example,
the actual line of interest, is the Speak line, which will read out the Text
property
of the individual item. You can replace this line, with any other activity you
want
performed on the individual item. The sub will take a TreeviewItems object, as
its
parameter. If you want the whole treeview iterated, from root and out, you could
simply do something like:
IterateTree TreeviewObject.TopLevel
Where TreeviewObject is an object pointing to a treeview, that you have defined.
In my testing app, I called it from the DialogEventHandler function of my
testing
dialog. Here I have defined a treview control, named TV_Test, and the sub is
called
when a button "BTN_SpeakTree) is pressed. The snip-it of the DialogEventHandler
then
looks like this:
Case "BTN_SpeakTree"
If DEvent = ButtonClicked Then
IterateTree DObj.Control( "TV_Test" ).TopLevel
DialogEventHandler = True
Exit Function
End If 'BTN_SpeakTree.
And, here is the iteration sub:
Sub IterateTree( TVItems)
Dim CurrentItem: Set CurrentItem = Nothing
Dim ItemNumber
For ItemNumber = 1 To TVItems.Count
Set CurrentItem = TVItems.Item( ItemNumber)
' The following line, is the actual action, performed on the individual item.
Replace
it with whatever you want:
Speak CurrentItem.Text &","
If CurrentItem.Children.Count >=1 Then
IterateTree CurrentItem.Children
Set currentItem = Nothing
End If 'CurrentItem.Children.Count >=1.
Next 'ItemNumber.
' Room Cleaning:
If Not CurrentItem Is Nothing Then Set CurrentItem = Nothing
If Not TVItems Is Nothing Then Set TVItems = Nothing
End Sub 'IterateTree.
Hope all of this will be of any help for the rest of the community. I am sure,
things
can be modified to work even more smoothly, and that you can change whatever
part
of it, to fit your personal scripting needs. But at least, I wanted to share
this,
since it is not something that first comes to mind, how to handle. Enjoy it. And
if anyone has any feedback on the other issues I presented in the initial
message
of mine, I am all greatful for whatever feedback you may have.
Thanks again,
----- Original Message -----
From:
David
To:
[email protected]
Sent: Thursday, April 11, 2013 11:14 PM
Subject: Treeview Questions - Still attempting to learn :)
I am still trying to wrap my brain around the complexity of a treeview, and how
to
gain the fullest benefit from this kind of control. Earlier, when asking, one of
you send me a code snip-it from one of his apps, holding some 600 lines. Thanks
to
you, and it got me somehow going. Yet, I don't follow all of your thinking, or
the
reason why you do this and that. That is one of the drawbacks of 600 lines of
coding.
Smile.
Allright, I have got that far, that I am able to fill in the information on the
tree,
and get it displayed in my dialog. So far, this works satisfactory. Now, I am
stuck
with a few challenges, most of all when comes to retrieve the needed information
from the treeview. I have a feeling, most of my getting stuck here, is due to a
lack
of understanding. That's why, I hoped to have some clarification on the
following
questions.
1. What is the exact benefit of the Text, as compared to the Data, field in a
treeview
item. OK, I do get the fact, that in case the same text could happen to be on
several
branches or leaves of the tree, the Data field could be used to distinguish the
one
occurrance from the other. But if i have a tree, where no text will appear more
than
once, is there any reason why I should bother about filling in the data field
for
each item? I.e, would there be any search feature or the like, that could be
quicker
done by iterating the tree-structure on the Data fields, compared to simply just
concentrating on the Text fields.
2. The treeview I am building, has checkboxes, which the user can check for each
item on the tree. I have searched the Reference manual, but not sure if I have
overlooked
anything. From what I can see, there is no way in determining whether a treeview
Item has been checked or not. I see the Selected feature, but from what my
testing
leads me to understand, this simply let's me know when an item has focus (that
is,
when the cursor is placed on the item, the Selected feature will be set). Is it
correct,
that there is no build-in feature, that would "fire", when a treeview item has
been
checked or unchecked? If this is the case, technically, why? We have features
for
Checkboxes, which will tell us when it is checked and not - and we have similar
features
for a multi-selection listbox. Why would there be no feature set, whenever a
treeview
item is checked?
3. Does anyone have a simple quick iteration routine, for "rushing" through a
whole
treeview, including all its branches and leaves. My treeview, might hold as much
as 9 sublevels, in addition to the root. And it might hold different amounts of
entries
on each branch or sublevel. I guess the best would be to use some For...Next
loops,
and somehow retrieve the Count property for each branch. But I have run my head
into
the wall, as to how to get through absolutely all the possible items on the
tree.
I guess, that is the one way to go, when iterating the different items, or am I
totally
lost in such an approach? Say for instance, the user would have been given the
chance
of searching for a given text, which would be the Text property of an item on
the
tree. I then guess, I will have to iterate all the current items on the tree,
looking
out for that particular text. And, that is why, I wondered if there was a simple
routine, that would perform such a "run-through", with relatively few lines of
coding.
Yep, I did read through I don't know how many pages, in the Reference manual,
and
I have been looking through quite a few lines of existing coding. I am sure, I
can
get on with this, if only I can wrap myself around a few corners. So, anyone who
has the urge to help me on getting those pieces of information straightend out,
thanks
to you, as it surely will help me crawling my way further on. :) Only hope my
questions
were clearly enough stated, that you will be able to give me the right push. :)