sorting data in a listbox

Discussion in 'Questions (Windows Mobile)' started by gjoisa, Dec 12, 2008.

  1. gjoisa

    gjoisa Active Member Licensed User

    Hi all !
    I am confused about sorting data in ascending mode in a listbox . Can any one help ?
     
  2. klaus

    klaus Expert Licensed User

    There is no Sort property or method for ListBox on the device.
    There is one for the desktop, but it needs the Door library.
    You can first put your data in an ArrayList, sort it and then transfer the sorted data to the ListBox.

    Best regards.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    And here is a code that implements klaus suggestion:
    Code:
    Sub Globals
        
    'Declare the global variables here.

    End Sub

    Sub App_Start
        Form1.Show
        SortListBox(
    "ListBox1")
    End Sub

    Sub SortListBox(List)
        ArrayList1.Clear
        
    For i = 0 To Control(List,ListBox).Count-1
            ArrayList1.Add(
    Control(List,ListBox).Item(i))
        
    Next
        ArrayList1.Sort(cNumbers)
        
    Control(List,ListBox).Clear
        
    For i = 0 To ArrayList1.Count-1
            
    Control(List,ListBox).Add(ArrayList1.Item(i))
        
    Next
    End Sub
    It uses an ArrayList named ArrayList1 to sort listboxes. Depending on your type of data you may need to change the line:
    Code:
    ArrayList1.Sort(...)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice