Reorder List Items in Vb.net

Hi! this is my another tutorial in vb.net that reorder an item in the listbox into descending order to ascending, or into ascending to descending order; vice versa. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add one TextBox named Texbox1 which serves as your input items in the Listbox. Create two ListBox named ListBox1 for your storage of input and ListBox2 for displaying the order list. Add also two Buttons named Button2 for adding an inputted item in the ListBox1 and to reorder the list of items in your ListBox1 and will be displayed in TextBox2. You must design your layout like this: design 3. Now put this code in your code module.
  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Dim tempNum As Integer
  5.         Dim tempString As String
  6.         Do
  7.             tempNum = ListBox1.Items.Count - 1
  8.             tempString = ListBox1.Items(tempNum)
  9.             ListBox2.Items.Add(tempString)
  10.             ListBox1.Items.RemoveAt(tempNum)
  11.         Loop Until tempNum = 0
  12.     End Sub
  13.  
  14.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  15.         ListBox1.Items.Add(TextBox1.Text)
  16.         TextBox1.Clear()
  17.     End Sub
  18. End Class

Explanation:

For Button2, it is the button used to add items from your inputted TextBox and then display the items in the ListBox1. Button1 is used for reordering the list of items in the Listbox1 and then displayed in ListBox2. If items in the Listbox1 is ascending, then the output in ListBox2 is in descending order. Otherwise, if items in the Listbox1 is descending, then the output in ListBox2 is in ascending order. We have initialized variable tempNum as Integer and variable tempString as String. Then we have created a Do until loop. Inside this loop is that the tempNum will hold the value of an index that the number of items in indexes will be minus 1 in ListBox1. Then the tempString will have this indexes of tempNum. Then the value now of tempString will be added to ListBox2 and all the items in ListBox1 will be removed.

Output:

output output Download the source code below and try it! :) Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment