VB.NET LListBox - Data Sorting

vb.net data sorting

This is a VB.NET tutorial, ListBox sorting ascending and descending.We sort when the user clicks a button,toggling between ascending and descending. This is the plan :

  • We first fill up an array with data.
  • Then bind the array to our ListBox.
  • When the user clicks the sort button we sort ascending first.
  • When he clicks again,we sort descending and vice versa.

Here's the 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

Best Regards.

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. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:


What do You Think

Dear readers drop us your comments below. We are building a community of students and learners. Start by dropping us your suggestions below. What tutorials do you want us to do for example? Where can we improve? What are some awesome resources out there? Do you have any code you want to share with us?
By the way that example or snippet you have lying in your computer can really help beginner programmers. We can share it here with other students.

Previous Post Next Post