I have a hierarchical list that works fine when I use listbox1.insertfolder. All nodes are displayed.
In the docs it says that listbox.expanded does not work when you use the insertfolder method.
How do you use .collapserow and .expandrow when you use the insertfolder and .insertrow methods?
If i try to collapse a row, expandrow fires first, before I can collapse it.
This code works, generates a list, but how do I collapse and expand rows if I am using this code or using the listbox insertfolder and insertrow methods?
This is my data structure:
SubjectId, Left,Right
1 root 0 , 2
2 subjects 1, 3
3 Computers 2, 4
4 programming Languages 3,5
5 real basic 4,0
6 xojo 4,0
7 computer Software 3,0
This code outputs this:
+Root
+Subjects
+Computers
+Computer Software
+Computer Programming
Xojo
Real Basic
- = disclosure triangle
Sub Buildcat( left as integer, therow as integer, indentedfolder as integer)
dim sql as string
sql = "SELECT * FROM Subject where Left = '" +str(left) + "'"
Dim mydata as recordset
mydata = DB.SQLSelect(sql)
If DB.Error Then
MsgBox("DB Error: " + DB.ErrorMessage)
Return
End If
therow = therow + 1
indentedfolder = indentedfolder + 1
If mydata <> Nil Then
While Not mydata.EOF
dim myleft, myright, mysubjectID as integer
dim subjectname as string
For i As Integer = 0 To mydata.FieldCount-1
if mydata.IdxField(i+1).Name = "SubjectName" then
subjectname =(mydata.IdxField(i+1).StringValue)
end if
if mydata.IdxField(i+1).Name = "Left" then
myleft = mydata.IdxField(i+1).IntegerValue
end if
if mydata.IdxField(i+1).Name = "Right" then
myright = mydata.IdxField(i+1).IntegerValue
end if
if mydata.IdxField(i+1).Name = "SubjectID" then
mySubjectID = mydata.IdxField(i+1).IntegerValue
end if
Next
if myright = 0 then
// has no children
listbox1.InsertRow(therow, subjectname,indentedfolder+1) // works
//listbox1.addrow(subjectname) // does not show indentation
listbox1.rowtag(listbox1.lastindex) = (str(mysubjectID) + "," + str(therow) + "," + str(indentedfolder))
else
listbox1.insertFolder(therow,subjectname,indentedfolder)
//listbox1.AddFolder(subjectname) // does not show Hierarchy
listbox1.rowtag(listbox1.lastindex) = (str(mysubjectID) + "," + str(therow) + "," + str(indentedfolder))
// recursive call
Buildcat(mySubjectID,therow,indentedfolder)
end if
mydata.MoveNext
Wend
end if
end sub