[Gambas-user] How to sort a TableView?

T Lee Davidson t.lee.davidson at ...626...
Fri Apr 1 02:21:12 CEST 2016


That's exactly what I needed, Gianluigi. Thank you.

It works well even preserving distinct rows with duplicate key values.

I added a few comments to your code and added it as an example to http://gambaswiki.org/wiki/comp/gb.qt4/gridview/sorted. (I 
hope that's okay with you. If not, please let me know and I'll modify or remove it.)


-- 
Lee
__________

"Artificial Intelligence is no match for natural stupidity."


On 03/31/2016 04:51 AM, Gianluigi wrote:
> Without using the database, have taught me so:
>
> Public Sub TableView1_Sort()
>     Dim Values, ValueSorted As New String[]
>     Dim Nx, iNx As Integer
>     Dim tmp As String
>
>      For Nx = 0 To TableView1.Rows.Max
>        Values.Add(TableView1[Nx, TableView1.Columns.Sort].Text)
>      Next
>      ValueSorted = Values.Copy()
>      ValueSorted.Sort(TableView1.Columns.Ascending)
>      For Nx = 0 To ValueSorted.Max
>        For iNx = 0 To TableView1.Columns.Max
>          Swap TableView1[Nx, iNx].Text,
> TableView1[Values.Find(ValueSorted[Nx], 0, Nx), iNx].Text
>        Next
>        Values.Clear()
>        For iNx = 0 To TableView1.Rows.Max
>          Values.Add(TableView1[iNx, TableView1.Columns.Sort].Text)
>        Next
>      Next
>      TableView1.Refresh()
> End
>
> Regards
> Gianluigi




More information about the User mailing list