I read the documentation and searched for a while but to no avail. Here’s my problem / idea:
I have a listbox with about 5 columns and between 50 and some hundred rows in them. The last two rows are nothing but the SUM of two of the columns; in a next step I’d like to have more than two rows in the list with grouped sums and stuff.
Now I want the user to be able to sort the values in the listbox (which works liks a charme, using ‘compareRows’) but … of course the two lines get sorted as well.
To get rid of them, I marked them with a special RowTag and have a little routine that takes the “special rows” out of the listbox or puts them back in - works nice & surprisingly fast.
So I want to take the special rows out (“remove_specials”) before sorting, sort - and then put them back in (“add_specials”).
The simplest thing I though of was to use the sortColumn-event, start with “remove_specials”, set the direction correctly, call “Me.sort”, then “add_specials” and return TRUE in the end to indicate that I don’t want this columns sorted (again).
But … Me.sort calls nothing but sortColumn again - and thus gives me a StackOverflow (and a headache).
Any solution to this knot in my brain? Except … sorting the data myself and re-popuplate the listbox every time - which gives a bit of other pain. I would rather want to use the sorting capabilities of the listBox, if possible, because the code is already there and works well enough for me.
Best thing is NOT to remove the specialrows. You can make sure they go to the bottom in CompareRow by checking if one or both are special rows and returning 1 or -1 depending on sort direction
Simply sorting the special rows to the bottom will not work, since Jan would now like to include “sub headers” within the list.
You could add a timer to your window with a very low period value. In sortColumn, set the mode of your timer to single. Xojo will hold off on executing the timer while it is sorting the columns. Just after the columns sort, your timer will fire. In the action of the timer, add the code you need for adding your special rows back to the list.
Thank you both for your quick answers. A short hack showed that Karen’s thinking was good for the need just to have the “sumline” at the bottom - here’s the code I put into CompareRows’ beginning (where I have 2 lines with the word “sumline” in the rowtag):
Dim mDirection As Integer = Me.ColumnSortDirection(column)
If Me.RowTag(row1) = “sumline” And Me.RowTag(row2) = “sumline” Then
result = 0
ElseIf Me.RowTag(row1) = “sumline” Then
result = mDirection
ElseIf Me.RowTag(row2) = “sumline” Then
result = mDirection * -1
Works perfectly. But thinking of if, Scott is right - if I want to not only have “sumline” at the bottom but also grouped “intermediary” sums, I’ll have to think some more. I’ll try and see what I come up with - but both of you helped me already! I can call it a day for today & play on tomorrow (since it’s nearly 8pm here and my kids are hungry!)
[quote=196253:@Scott Siegrist]Simply sorting the special rows to the bottom will not work, since Jan would now like to include “sub headers” within the list.
As long as he can recognize what regular row belong with what group and what order the groups will be in the same idea in CompareRows can work for subheadings.