Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# sort not working using a listbox in vb.net 2005

Posted on 2007-11-14
Medium Priority
1,008 Views
Hi,

I have a listbox with the following data in it: -

12
8
13
2
11
9

I would like to sort it in numerical order. I have set sorted as true but it does not  do it. What am I doing wrong please.

Many Thanks
Lee
0
Question by:ljhodgett
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

Author Comment

ID: 20281296
sorry code I'm using is: -

For i = 0 To 5

Dim r As New Random
retry_Number:
Found = False
Returned_Number = Convert.ToInt32(r.NextDouble * 49)
If Returned_Number = 0 Then
GoTo retry_Number
End If
x = 0
For x = 0 To lstLuckyDip.Items.Count - 1
If lstLuckyDip.Items.Count > 0 Then
lstLuckyDip.SelectedIndex = x
If Returned_Number = lstLuckyDip.Text Then
Found = True
End If
End If
Next
If Found = False Then
Else
GoTo retry_Number
End If
Next
0

LVL 48

Expert Comment

ID: 20281357
You can set the sorted = false and add in the of you routine (after fill the code):

lstLuckyDip.Sorted = True

Notice that this will order by the first number so will end like this:

11
12
13
2
9
8

You can change the format to 02,08,09 and it sorts right.
0

Author Comment

ID: 20281573
right ok,

how would I sort it so it would be: -

2
8
9
11
12
13

Many Thanks
Lee
0

LVL 48

Accepted Solution

jpaulino earned 2000 total points
ID: 20281686
The easy way (at least for me) is to change you Returned_Number to 2 numbers like 02, 08, 09.

You can do that using padleft like this

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
###### Suggested Courses
Course of the Month9 days, 9 hours left to enroll