Thanks for all responses. I thought there is a simpler way to to that without copying data back and forth. My solution is basically a custom sortwith using a base array for the initial sort and an index array of integers to sort with.
The index array is later used to rearrange all other items to keep the data consistent as the
rows are tied like a listbox but only virtual. Assuming you sort ascending you can call sortByIndex rightaway, otherwise call reverse the index array and do the sort.
[code]Private Function arrayFromDown(indices() as integer) As integer()
dim c as integer= indices.Ubound
dim n(), idx as integer
redim n( c )
for i as integer = c downto 0
n( idx ) = indices( i )
idx=idx+1
next
return n
End Function[/code]
[code]Private Function sortByIndex(inData() as Text, sortindex() as integer) As Text()
dim c as integer = inData.Ubound
dim buff(-1) as Text
redim buff( c )
for index as integer=0 to c
buff(index) = inData( sortindex( index ) )
next
return buff
End Function[/code]
[code]Private Function getSorter(columnIndex as integer,type as SortType) As integer()
dim c as integer= self.rowCount-1
dim n() as integer
if c<=-1 then
return n
end if
redim n( c )
dim sortData() as Text
redim sortData( c )
dim targetColumn as ColumnTable = self.columns(columnIndex)
for idx as integer=0 to c
sortData(idx) = targetColumn.data(idx)
n( idx ) = idx
next
sortData.SortWith( n )
if type=SortType.Descending then
return self.arrayFromDown( n )
else
return n
end if
End Function[/code]
[code]Sub sort(columnIndex as integer, type as SortType)
if not (columnIndex>-1 and columnIndex<self.columnCount) then
self.setError( CurrentMethodName, 30 )
return
end if
dim indices() as integer = self.getSorter(columnIndex, type)
if indices.Ubound<0 then
return
end if
for each column as ColumnTable in self.columns
column.data = self.sortByIndex( column.data, indices )
next
End Sub[/code]
So you’re practically reordering all arrays yourself.