Hi there… I have an hierarchical listbox where I parse an xml file. So I need to have all folders expanded but my code seems work bad and (after hours) I don’t understand why… Thanks in advance for your help…
Here my code:
[code]dim i,o,u As Integer
for i=1 to 5 'because I have maximum 5 inner folders but I can’t know how many folders I’ll have
u=mylist.LastIndex
for o=0 to u
if mylist.RowIsFolder(o) then
mylist.Expanded(o)=true
end if
Next
Next[/code]
[quote=415370:@Stefan Adelsberger]Simply do a loop and expand all entries?
[code]
For i As Integer = 0 To Listbox1.ListCount - 1
Listbox1.Expanded(i) = True
Next[/code][/quote]
Ok using listcount instead of lastindex seems working nice, but I have to execute the loop many times to expand all subfolders. I think I’ll use a “loop until” …
Nice suggestion. Thanks
Here the definitive solution… Thanks to Norman Palardy! @Norman Palardy
[code]Dim toExpand() As Integer
For i As Integer = mylist.ListCount-1 DownTo 0
If mylist.RowIsFolder(i) And mylist.Expanded(i) = False Then
toExpand.Append i
End If
Next
While toExpand.Ubound >= 0
// expand all these
For i As Integer = toexpand.Ubound DownTo 0
mylist.Expanded( toExpand(i) ) = True
Next
Redim toExpand(-1)
// get whats left to expand
For i As Integer = mylist.ListCount-1 DownTo 0
If mylist.RowIsFolder(i) And mylist.Expanded(i) = False Then
toExpand.Append i
End If
Next
[quote=415491:@Sergio Tamborini]Here the definitive solution… Thanks to Norman Palardy! @Norman Palardy
[code]Dim toExpand() As Integer
For i As Integer = mylist.ListCount-1 DownTo 0
If mylist.RowIsFolder(i) And mylist.Expanded(i) = False Then
toExpand.Append i
End If
Next
While toExpand.Ubound >= 0
// expand all these
For i As Integer = toexpand.Ubound DownTo 0
mylist.Expanded( toExpand(i) ) = True
Next
Redim toExpand(-1)
// get whats left to expand
For i As Integer = mylist.ListCount-1 DownTo 0
If mylist.RowIsFolder(i) And mylist.Expanded(i) = False Then
toExpand.Append i
End If
Next
Wend[/code][/quote]
Did you try this simple loop?
I wrote an example project and it works:
[code]
For i As Integer = 0 To Listbox1.ListCount - 1
Listbox1.Expanded(i) = True
Next[/code][/quote]
I think this is the first solution I’ve tried but something is gone bad… This is work and is simpler than preview solution. Thanks…