Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sort not working using a listbox in vb.net 2005

Posted on 2007-11-14
4
Medium Priority
?
1,010 Views
Last Modified: 2013-11-26
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
Comment
Question by:ljhodgett
  • 2
  • 2
4 Comments
 

Author Comment

by:ljhodgett
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
                lstLuckyDip.Items.Add(Returned_Number)
            Else
                GoTo retry_Number
            End If
        Next
0
 
LVL 48

Expert Comment

by:jpaulino
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

by:ljhodgett
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

by:
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

lstLuckyDip.Items.Add(Returned_Number.ToString.PadLeft(2,"0"))
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question