Hi group, I have a listbox, loaded with data in ascending order… I thought that once the data was loaded, by clicking on a column, the data would be sorted in ascending or descending order. If I click on the “Gross F.” column the totals are sorted incorrectly, what does it depend on? Is there a solution?
The default uncontrolled sort is framework level String sorting. Byte code position, if that’s what you were looking for.
Yes, you can control the sort yourself with the RowComparison event.
Ok TIM, I have to study then. I have a little difficulty with English
I tried to load the already sorted data with the second code, but it doesn’t sort anything
rows = db.SelectSQL("SELECT Ditta,SUM(Totale) as Totals from Ingressi Group by Ditta order by SUM(Totale) DESC")
and then I load the data that in my opinion should have been sorted
While Not Rows.AfterLastRow
ListBoxAvere.AddRow("0", rows.Column("Ditta").StringValue.ConvertEncoding(Encodings.WindowsANSI),"0", "00/00/0000", "0" , "0", Format(rows.Column("Totals").CurrencyValue,"-##.00"), "0")
TotaleLordo=TotaleLordo+rows.Column("Totals").CurrencyValue
rows.MoveToNextRow
Wend
That will affect the order in which the data comes out of the database, but it does not affect the order in which the Listbox will display the rows after a user clicks a header to sort. Sorting at that point is handled by the Listbox not the Database.
You will need to implement that RowComparison event to do sorting beyond simple string sorting when the user clicks a header.
Hmmm, is this another instance of where a user might think there is a tight connection between a database and a listbox? When in fact there isn’t? This occurs because all the listbox examples show a listbox being loaded from a database.
I gave up using the Xojo sort, just reload the data from the database using the appropriate ORDER BY depending on which header the user clicked.