Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8666749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:48:26+00:00 2026-06-12T17:48:26+00:00

Im trying to sort a listbox full of numbers numerically. Why doesnt this work?

  • 0

Im trying to sort a listbox full of numbers numerically. Why doesnt this work?

        {
            ArrayList Sorting = new ArrayList();
            Sorting.Add (lbNumbers.Text);
            int[] items = new int[Sorting.Count];
            Sorting.CopyTo(items);
            Array.Sort(items);
            lbNumbers.Items.Add(items);

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:48:28+00:00Added an answer on June 12, 2026 at 5:48 pm
    ArrayList Sorting = new ArrayList(); 
    
    foreach (var o in listBox1.Items) {
        Sorting.Add(o);
    } 
    
    Sorting.Sort(); 
    
    listBox1.Items.Clear();
    
    foreach (var o in Sorting) {
        listBox1.Items.Add(o); 
    }
    

    ADDED: For sort in descending order,

    1.Create a class ReverseSort as shown below:

    // implementation:
    public class ReverseSort : IComparer
    {
        public int Compare(object x, object y)
        {
            // reverse the arguments
            return Comparer.Default.Compare(y, x);
        }    
    }
    

    2.Replace the code line of Sort with this line:

    Sorting.Sort(new ReverseSort());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to sort this array of objects according to (1) depth and (2) weight,
Been trying to sort this one out for a while. I'd really appreciate any
I am trying to sort a two-dimensional array by a timestamp column Descending. This
I am trying to sort a Vector list using the Java Collections frameworks. This
I'm trying to sort an array in descending order in Java using this code:
Im trying to sort through an arraylist of objects by a particular value within
Been trying to sort this for over a day now, and I am sure
I'm trying to sort an array that looks like this: var dateGroups = [
I am trying to sort an array by a non standard sorting of an
I'm setting up a new store using 1.4.1 I'm trying sort the products in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.