ListBox, Sort and Selection

I think I have done too many hours today !

Should be easy, but…

How can I scroll a listbox to show the selected item, once the user has clicked a header cell to sort?

What I need to do is once the sort has finished, scroll the selected item back into view.

Can someone help?

Thanks

Phil

Look at the ScrollPosition property.

I had also troubles, when I tried to sort a column, where there were numbers of different length in it. (Because the sort ist 1.11 then 111.2 and then again 1.13)

So if you got this also, here my simple solution.

For each column with any amounts (money or other things) you create a column at the end, which is to narrow to be seen.
In this column you write a number wich is (10000000000 - amount)
Afterwards you sort this column and the numbers are sorted in the amountcolumn.

Eli Ott:
The Scrollposition is also somehow a little bit difficult, because if you alter the amounts of rows after the selection with cellclick, it is very difficult, to come to the right position.

Or you could just use ListBox.CompareRows which is the generally accepted practice.

// Example for forum Function CompareRows(row1 as Integer, row2 as Integer, column as Integer, ByRef result as Integer) As Boolean // we want a numeric sort for for column 0 -and column 8 select case column case 0, 8 result = (val(me.Cell(row1, column)) - Val(me.Cell(row2, column))) Return True Else Return False end Select End Function

I found now this function, but I think you forgot the “sign” before the equitation ??

result = SIGN(val(me.Cell(row1, column)) - Val(me.Cell(row2, column)))

If you need signed ints then modify it. I didn’t. The point of my post was to show you the CompareRows method.