' Gambas class file
Private aState As Integer[]
Private aNamesSorted As New String[]
Private aAgesSorted As New Integer[]
Private aNames As String[] = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
Private aAges As New Integer[]
Private iLast As Integer = -1
Public Sub Form_Open()
Dim i As Integer
For i = 0 To aNames.Max
aAges.Add(Rand(1, 100))
Next
aState = [0, 0]
FormatTable(TableView1)
aNamesSorted = aNames.Copy()
aAgesSorted = aAges.Copy()
DataTable(TableView1)
End
Public Sub FormatTable(tv As TableView)
Dim r As Integer
tv.Header = GridView.Horizontal
tv.Columns.Count = 2
tv.Rows.Count = aNames.Count
'tv.Sorted = True
tv.Columns[0].Title = ("Name")
tv.Columns[1].Title = ("Age")
End
Public Sub DataTable(tv As TableView)
Dim r As Integer
For r = 0 To aNamesSorted.Max
tv[r, 0].Text = aNamesSorted[r]
tv[r, 1].Text = aAgesSorted[r]
Next
End
Public Sub TableView1_ColumnClick(Column As Integer)
Dim age As Integer
Dim Name As String
Dim id As Integer
Select Column
Case 0
aNamesSorted.Clear
aAgesSorted.Clear
If aState[Column] = 0 Then
aNamesSorted = aNames.Copy()
aAgesSorted = aAges.Copy()
aState[Column] = 1
Else
If aState[Column] = 1 Then
aNamesSorted = aNames.Copy().Sort(gb.Ascent)
aState[Column] = -1
Else
aNamesSorted = aNames.Copy().Sort(gb.Descent)
aState[Column] = 0
Endif
For Each Name In aNamesSorted
id = aNames.Find(Name)
If id > -1 Then
aAgesSorted.Add(aAges[id])
Endif
Next
Endif
Case 1
aNamesSorted.Clear
aAgesSorted.Clear
If aState[Column] = 0 Then
aAgesSorted = aAges.Copy()
aNamesSorted = aNames.Copy()
aState[Column] = 1
Else
If aState[Column] = 1 Then
aAgesSorted = aAges.Copy().Sort(gb.Ascent)
aState[Column] = -1
Else
aAgesSorted = aAges.Copy().Sort(gb.Descent)
aState[Column] = 0
Endif
For Each age In aAgesSorted
id = aAges.Find(age)
If id > -1 Then
aNamesSorted.Add(aNames[id])
Endif
Next
Endif
End Select
DataTable(TableView1)
End
(19-04-2021, 23:01)tincho escribió: Jeje, no lo has mirado bien. hay 3 estados no 2. sin ordenar, ascendente y descendente. el tercer clic vuelve al estado inicial