[Gambas-user] How to read keys from a TreeView

Rolf-Werner Eilert eilert-sprachen at ...221...
Mon Jan 12 16:09:55 CET 2009


Benoit Minisini schrieb:
> On lundi 12 janvier 2009, Rolf-Werner Eilert wrote:
>> Proceeding to convert a Gambas1 app to Gambas2, I found that reading key
>> values or stepping through the values is different now.
>>
>> The TreeView shows names of persons sorted under groups/classes/filters
>> sorted under years sorted under a root header, in brief:
>>
>> Root1
>> 	2004
>> 	2005
>> 	2006
>> 		Group1
>> 		Group2 <-- Cursor
>> 			John
>> 			Benoit
>> 			Michael
>> 			Rolf
>> 		Group3
>> 	2007
>> 	2008
>> Root2
>>
>> What I want is when the cursor is on Group2 and I call my function, it
>> expands and reads all keys of the names within this group.
>>
>> This is the code in Gambas1:
>>
>>       baum.Current.Expanded = TRUE
>>
>>       namenKeys.Clear
>>
>>       FOR i = 1 TO baum.Current.Children
>>         baum.Item.MoveBelow
>>         IF Left$(baum.Item.Key, 1) = "#" THEN
>>           namenKeys.Add(baum.Item.Key)
>>         ELSE
>>           BREAK
>>         END IF
>>       NEXT
>>
>> "baum" is the TreeView, "namenKeys" is an array that should return the
>> keys which were found. The idea was to read the keys either up to the
>> number of children or until the next key doesn't have a "#".
>>
>> This doesn't run in Gambas2 this way, but I didn't find a way to make it
>> run. MoveBelow doesn't seem to exist anymore (Gambas2 won't show an
>> error, however), and I tried any possible combination of using
>> MoveAfter() with Item and Current, but to no avail.
>>
>> So, can anybody help here?
>>
>> Thanks so much!
>>
>> Rolf
>>
> 

Thanks Benoit for this insight...

> MoveBelow() is a method of TreeView in Gambas 2, and moves the internal cursor 
> one item below. (In Gambas 1, this method did not work in all cases).
> 
> But as you want the child items of a node, you must not use MoveBelow(). It 
> moves one item below, whether it is a child or not of the initial parent 
> item. 
> 


> So if one of the child has children too, you routine won't work.

You are right, and now the "BREAK" clause in my code becomes superfluous.

> 
> You must use MoveNext() instead:
> 
>   baum.Current.Expanded = TRUE
> 
>   namenKeys.Clear
> 
>   ' Move the internal cursor to the current item
>   baum.MoveCurrent()
>   ' Then move to the first child of the current item
>   baum.MoveChild()
> 
>   ' While the internal cursor is valid, i.e. while there is
>   ' a child to look at.
>   WHILE baum.Available
> 
>     IF Left$(baum.Item.Key, 1) = "#" THEN
>       namenKeys.Add(baum.Item.Key)
>     ELSE
>       BREAK
>     END IF
>     
>     ' Move to the next sibling item, i.e. the next item having 
>     ' the same parent.
>     baum.MoveNext()
> 
>   WEND

Thank you very much for that code, it runs perfectly (of course... :-) ).


> 
> See the documentation of the methods in the wiki to know what they are doing 
> exactly.

You see, I have my problems with reading documentations. Often I just 
can't see where to go and what's important. Maybe that's why I've never 
become a professional programmer... :-(

But when I have a small example of what to do and how, this will mostly 
help me understand reading the documentation.


Regards

Rolf




More information about the User mailing list