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?
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 …
[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.
[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.