Listbox CollapseRow, ExpandRow, MouseClick Events

Hi All -

I’m on Windows Xojo 2014R2.

I am using a Hierarchical Listbox that is displaying data in a 2D array. The back-end array has ‘columns’ (second index) for ‘isExpanded’, ‘isChild’ and then there is a routine that basically goes through the array by ‘row’ (first index) and if ‘isExpanded’ then I addrow for ‘isChild’.

Here is the problem … When a user clicks to, lets say, collapse a ‘folder’ in the listbox it triggers the ‘CollapseRow’ event. I assign ‘isExpanded’ on the backend to false and run the routine to handle updating the front-end. When I run the routine, however, which resets the .Expanded property of the folders in the listbox, it triggers the ‘ExpandRow’ and ‘CollapseRow’ events again! I end up in an endless loop!!

I thought I was being slick by simply using the ‘MouseClick’ event. This would work by basically reading the .Expanded property for each row of the listbox, setting the backend array, and then callling the routine to update the frontend. However, this routine runs before the .Expanded propery is updated! So it ‘works’ except that when the disclosure triangle is OPEN everything is collapsed and when the disclosure triangle is closed everything is expanded.

Any ideas? Users will be able to update the .Expanded status of a row by other ways in the program, so i want to be able to do this both programmatically AND by clicking the disclosure triangle.

Sorry was able to resolve this.

Basically, if collapseRow we check on backend if array isExpanded=false and if not, make it false, then call the updateFrontEnd routine. This time, the collapseRow gets triggered again but when evaluates isExpanded, it is already false. This avoids the endless loop. Seems a little inefficent but it works.

No it still isn’t working correctly – is there a way to set the listbox.Expanded property for a row without triggering the collapseRow or expandRow event?

I think you are going about this backward:

Setting the listbox.Expanded property in code is equivalent to pressing the widget (triangle or plus/minus box depending on operating system) of the parent row. In response to either, the appropriate event is triggered. In the ExpandRow event you add the additional rows and populate them from your backend array (and probably mark them in the backend array as showing if that is necessary in your application). In the CollapseRow event you remove the dependent rows (and probably mark the corresponding entries in the array as not showing). The visual appearance of the listbox should be handled automatically by the framework. It is also nice that the framework will not trigger the same event twice if you set .Expanded to the same value twice in a row.

BTW, CellTag and RowTag are extremely useful for bookkeeping in the context of hierarchical listboxes. You might find it useful to store the row index of your array in the corresponding RowTag in the ExpandRow event. That way you can point back at your array, e.g. when you are removing the same row in the CollapseRow event.

The docs really weren’t clear and did only mention the user pressing the disclosure. But that has been corrected.

You do not need to remove the rows. The listbox does that for you. You just need to update your data structure with the state of the rows.