Sorting the other columns in a listbox

Hi Xojo gurus

I have a listbox that a user can sort by clicking in the column header. One column is called “Category”. If there are many rows with the same Category, how do the other columns get sorted within the Category list?

In the example below - I have sorted the columns by clicking on Category. I have 4 rows with “Telephone”. In those rows, the Dates and other values seem to be sorted randomly. Can anyone explain how the other columns are sorted when there is more than one identical item in the sorted column?

Other rows will be sorted randomly.

You will need to implement the CompareRows event and define your own column priority for sorting.
For example if sorting by Category, should it then sort by Date or by Business Cost …

Rob… Hope this helps.

[code]Private Sub DoSort(onColumn as Integer, order as sortOrder)
dim columnContents(-1) as string
dim sortWith(-1) as integer
dim r,c as integer

if onColumn < ColumnCount and onColumn >= 0 then

for r=0 to RowCount-1
  columnContents.Append cell(r, onColumn)
  sortWith.Append r
next
columnContents.SortWith(sortWith)

for c=0 to ColumnCount-1
  redim columnContents(-1)
  
  for r=0 to RowCount-1
    columnContents.Append cell(r, c)
  next
  
  if order = ascending then
    
    for r=0 to RowCount-1
      cell(r, c) = columnContents(sortWith(r))
    next
    
  else
    
    for r=0 to RowCount-1
      cell(RowCount-r-1, c) = columnContents(sortWith(r))
    next
    
  end if
next

end if

System.DebugLog(“Lets See.”)

End Sub
[/code]

If you figure out a way to make sure the row tags etc follow the rows after sorting more power to us.

Thank you both. I suspected as such. I have a CompareRows event implemented already, and I will make use of it to sort by Date within a sorted column.

Rob… The sort method I provided will sort all columns based on the column clicked on… call it on the column click event.
?

That should happen automatically (if you do it in CompareRows).

[quote=383234:@Brian O’Brien]Rob… The sort method I provided will sort all columns based on the column clicked on… call it on the column click event.
?[/quote]
Better to implement comparerows as everything else is handled for you.

@Tim Hare What about the row labels and tags, styles do they follow in the sort?

Yes.

It maybe that my IDE is out of date, but I do not see a CompareRows method to implement mentioned in the docs.
Only for listbox and not for weblistbox

I don’t see any mention of weblistbox in the thread, just listbox. I assumed we were talking about desktop.