Database & Listbox: How to do sort?

Hi all,

I have a ListBox which displays records from a database.

To speed the ListBox up I would like to have the record in the RowTag and only draw the visible rows.

But how would I implement sorting the ListBox (for example by clicking one of the column headers)?

Thanks for any pointers

Markus

Your listbox should have an array with the data, resort this and then show again the rows that are visible. Or sort via SQL.

[quote=58524:@Markus Winter]Hi all,

I have a ListBox which displays records from a database.

To speed the ListBox up I would like to have the record in the RowTag and only draw the visible rows.
[/quote]

Not sure what you are doing… If you are adding your records to the rowtags and adding a row in the listbox for each record and so NOT using your own scrollbar (In other words, if i understand what you are saying, it’s not a data on demand type situation)… why not put the string values in the cell as as the listbox only draws visible rows anyway? (At one time that was not the case but has been for many years now)…

If you are NOT adding rows for each record but keeping the the # of rows constant at the # displayed and when scrolling using your own scrollbar to change the contents of the rows (moving around row tags) then you should do what Beatrix says…

Do the sorting yourself as he says in the ListBox.HeaderPressed event and update the Rowtags there, but either prevent the built-in sort or returning 0 in the CompareRows event, and invalidate teh listbox if needed.

If you are mot doing that, then standard answer to listbox sorting is to use the CompareRows event using data from the rowtag if needed.