Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3963

Manually sorting a listbox

$
0
0

Hey all, I am manually trying to sort a listbox as it contains more than just string data and the built in column sorts only handle alphabetical data. However my function works up until I try to add a row to my new desktoplistbox using an array… I have no idea why but it silently fails and does not add rows despite my array being populated. Any help would be appreciated!

Public Function SortByColumn(listbox as DesktopListbox, sortColumnNum as integer, columnIsString as Boolean = True) As DesktopListBox
  Var resultsListbox As DesktopListBox= New DesktopListBox
  Var modListbox() As DesktopListBoxRow
  Var temp As DesktopListBoxRow
  
  For Each row As DesktopListBoxRow In listbox.Rows
    modListbox.add(row)
  Next
  
  If(modListbox<>Nil) Then
    If(columnIsString) Then
      For i As Integer= 0 To modListbox.Count-1
        For j As Integer= 0 To modListbox.Count-1
          If(modListbox(i).CellTextAt(sortColumnNum).Trim<_
            modListbox(j).CellTextAt(sortColumnNum).Trim) Then
            temp= modListbox(i)
            modListbox(i)= modListbox(j)
            modListbox(j)= temp
          End
        Next
      Next
    Else
      For i As Integer= 0 To modListbox.Count-1
        For j As Integer= 0 To modListbox.Count-1
          If(modListbox(i).CellTextAt(sortColumnNum).Trim.ToInteger<_
            modListbox(j).CellTextAt(sortColumnNum).Trim.ToInteger) Then
            temp= modListbox(i)
            modListbox(i)= modListbox(j)
            modListbox(j)= temp
          End
        Next
      Next
    End
  End
  
  Var tempArr() As String
  For k As Integer= 0 To modListbox.Count-1
    tempArr.RemoveAll
    For t As Integer= 0 To listbox.ColumnCount-1
      // System.DebugLog(">"+modListbox(k).CellTextAt(t)+"<")
      tempArr.Add(modListbox(k).CellTextAt(t))
    Next
    System.DebugLog(tempArr(0)+ " " +tempArr(1)+ " " +tempArr(2)+ " " +tempArr(3)+ " " +tempArr(4))
    resultsListbox.AddRow(tempArr) // WHY??????
    System.DebugLog("Row Count: " + resultsListbox.RowCount.ToString)
  Next
  
  Return resultsListbox
  
End Function

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 3963

Trending Articles