Results 1 to 4 of 4

Thread: Is it possible to reverse the order of a listbox items?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    4

    Is it possible to reverse the order of a listbox items?

    Is it possible to reverse the order of the items in a listbox?

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Is it possible to reverse the order of a listbox items?

    how about?,,..

    Code:
    With ListBox1
        Dim items(.Items.Count - 1) As Object ' create array to hold listbox items.
        .Items.CopyTo(items, 0) ' copy listbox items to array.
        .Items.Clear()          ' clear listbox
        Array.Reverse(items)    ' reverse array
        .Items.AddRange(items)  ' add array to listbox. 
    End With

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: Is it possible to reverse the order of a listbox items?

    Or:

    Code:
    Dim items() As Object = ListBox1.Items.Cast(Of Object).Reverse.ToArray
    ListBox1.Items.Clear
    ListBox1.Items.AddRange(items)

  4. #4
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Is it possible to reverse the order of a listbox items?

    Else:
    Code:
    For i As Int32 = 0 To ListBox1.Items.Count - 2
       ListBox1.Items.Insert(i, ListBox1.Items(ListBox1.Items.Count - 1))
       ListBox1.Items.RemoveAt(ListBox1.Items.Count - 1)
    Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width