VB.NET LListBox - Sorting Data in Ascending and Descending Manner

| Page Views: 1820 vb.net data sorting

Sorting data is such important operation when it comes to dealing with modern software. It helps the user easily reach the specific data he needs without necessarily having to go through the whole dataset line by line. This is a VB.NET tutorial.

We see how to sort a listbox data in an ascending or descending order. This is a very basic example. We simply use an Array to sort and reverse our data. The array is then bound to a listbox.

Questions this Examples helps answer.

  • How to sort data in ascending and descending manner.
  • How to sort data in vb.net listbox.
  • How to sort and reverse an array in vb.net.
  • VB.NET ListBox data sorting example.


We assume that you can drag and drop a listbox into a winform project. Just drag a listbox and a button that shall sort our data in ascending and descending manner. We also used the metro theme in our project. There is a tutorial on how to install a metro theme here.


  • Here's the screenshot of the project.

VB.NET ListBox Sorting Ascending and Descending.

  • We can insert,select, update and delete data to and from ms access database.

VB-NET ListBox Sort

Source Code

Lets have a look at the source code.


Public Class Form1

    ReadOnly spacecrafts As String() = {"Kepler", "Casini", "Voyager", "New Horizon", "James Web", "Apollo 15", "Enterprise", "WMAP", "Spitzer", "Galileo"}
    Dim ascending As Boolean = True

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub

    Private Sub Populate()
        For Each s In spacecrafts
    End Sub

    Private Sub Sort(ByVal asc As Boolean)
        If asc Then
        End If

        'FILL SORTED
    End Sub

    Private Sub sortBtn_Click(sender As Object, e As EventArgs) Handles sortBtn.Click
        ascending = Not ascending
    End Sub

End Class




How To Run

  1. Download the project above.
  2. You'll get a compressed file. Unzip it.
  3. Open Visual Studio.
  4. Go to File --> Open --> Project/Solution.
  5. Open the project in visual studio.
  6. That's it.


We've seen how to sort a listbox in both an ascending and descending manner.



  • Visit our channel for more examples like these.



How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section.

About Me.

After completing his Software Engineering bachelors program, Oclemy(Clement Ochieng) these days is a man of two lives. At day he works for a startup in Nairobi, Kenya. At night he works tirelessly on building ProgrammingWizards TV, a tv channel for student coders and this website to help share the source code. In between he practices Meditation and Self actualization to help him keep balance. He also likes going for long solo walks to connect more with nature.


What do You Think

Previous Post Next Post