The listbox in 2014r2 has some buggy behavior. I’ve found a workaround but want to report.
OK. So first off, the idea is that the listbox is going to present data contained in a multidimensional array on the backend. I’m using a version of this in another program. The backend array has 2 extra columns, 1 specifies folder versus not, the other specifies expanded vs. not. (in practice this can be condensed into 1 extra column because only folders can be expanded or not, but for ease of following the program i broke it into two in the example below).
There is a routine, updateFrontEnd, that brings the listbox into alignment with the settings stored in the backend array. Unfortunately, when the .expanded property is set programmatically in this routine, it also triggers the ExpandRow and/or CollapseRow events of the listbox. I consider this to be the first bug - the documentation says these events are triggered when the user CLICKS the disclosure triangle, NOT when the property is set/changed.
Second, you’ll notice that I add my folders and rows in 1 of 2 ways.
Listbox1.AddFolder(mydata(i,0))
//Listbox1.InsertFolder(row, mydata(i,0), 0)
Listbox1.AddRow(mydata(i,0))
//Listbox1.InsertRow(row, mydata(i,0), 0)
So, when using addrow/addfolder, the folders and rows populate as expected BUT the indentation is all messed up. Some of the top level folders have indentation, as if they were regular rows. (That is, the disclosure triangle is inline with the beginning of the text for a regular row)
The indentation property only seems to be accessible when ‘inserting’ a folder or row, so I switched to using the ‘insert’ property for the folder only (at first) because this was where the indentation was wrong. WOW that caused problems. If using ‘insertfolder’ and ‘addrow’, then when users click expand or collapse the program completely goes awry, adding disclosure triangles where they shouldn’t exist, etc.
The crazy thing here is that this only is a problem when the ‘updateFrontEnd’ routine is called from the collapseRow or expandRow event. When I use the pushbutton to call the routine (after changes have been made) it works fine.
Finally, if using insertfolder AND insertrow, everything works as expected. No harm, no foul - as all is working - but this seems like buggy behavior and not sure if it has been addressed in later versions, as 2014r2 is the latest to which I have access.
Set up the following simple program to replicate this (again, done on 2014r2).
- The following properties for window1:
mydata(-1,-1) as string
userClick as boolean = false
- The following methods for window1.
Constructor:
[code] // Calling the overridden superclass constructor.
Super.Constructor
redim mydata(25,2)
dim i as integer
mydata(0,0)=“folder1”
mydata(3,0)=“folder2”
mydata(7,0)=“folder3”
mydata(10,0)=“folder4”
mydata(16,0)=“folder5”
mydata(21,0)=“folder6”
mydata(0,1)=“folder”
mydata(3,1)=“folder”
mydata(7,1)=“folder”
mydata(10,1)=“folder”
mydata(16,1)=“folder”
mydata(21,1)=“folder”
mydata(0,2)=“true”
mydata(3,2)=“true”
mydata(7,2)=“true”
mydata(10,2)=“true”
mydata(16,2)=“true”
mydata(21,2)=“true”
dim parentF as integer=0
dim childnum as integer =0
for i=0 to 25
if mydata(i,1)=“folder” then
parentF=i
childnum=1
end if
if mydata(i,1)<>"folder" then
mydata(i,0) = "child"+str(childnum)
mydata(i,1) = "child"
mydata(i,2) = str(parentF)
childnum=childnum+1
end if
next
updateFrontend[/code]
UpdateFrontEnd
[code] listbox1.DeleteAllRows
dim row as integer =0
dim i as integer
for i=0 to 25
//MsgBox “i=”+str(i)+": “+mydata(i,0)+”, “+mydata(i,1)+”, "+mydata(i,2)
if mydata(i,1)=“folder” then
Listbox1.AddFolder(mydata(i,0))
//listbox1.InsertFolder(row, mydata(i,0), 0)
if mydata(i,2)="true" then listbox1.Expanded(listbox1.LastIndex)=true
if mydata(i,2)="false" then listbox1.Expanded(listbox1.LastIndex)=false
listbox1.RowTag(row)=i
row=row+1
else
dim myParent as integer = val(mydata(i,2))
if mydata(myParent,2)="true" then
listbox1.AddRow(mydata(i,0))
//listbox1.InsertRow(row, mydata(i,0), 0)
listbox1.RowTag(row)=i
row=row+1
end if
end if
next[/code]
- On the front end, listbox1 and pushbutton1 objects.
Listbox1 has the following events:
collapserow
[code] if userClick=false then return
userClick=false
dim backend_index as integer = listbox1.RowTag(row)
mydata(backend_index,2)=“false”
updateFrontend
[/code]
expandrow
[code] if userClick=false then return
userClick=false
dim backend_index as integer = listbox1.RowTag(row)
mydata(backend_index,2)=“true”
updateFrontend[/code]
mousedown
userClick=true
pushbutton1 has action event
//refresh the frontend
updateFrontend