how do i sort information in a listbox by name (that is, alphabetical order)? im doing c# programming n using microsoft visual studio .net 2003.

If you are using a SELECT statement, which I would assume you are, just add an ORDER BY clause to that statement and voila.

Ok, you are a bit unclear here with the issue you are facing.
Would you like to populate listBox with already sorted items, or would you like to sort items, which are already in the listBox?

Here is the code which shows you both:
(ps: button click even reverses the list, so you can see the difference in the code)

public Form1()
            string[] array = new string[] { "D", "C", "A", "E", "B" };

        private void buttonInvert_Click(object sender, EventArgs e)
            int rows = listBox1.Items.Count;
            string[] array = new string[rows];
            for(int i=0;i<listBox1.Items.Count;i++)
                array[i] = listBox1.Items[i].ToString();


You can set ListBox's property 'Sorted' to 'true'. If you are using an array, make sure that sorting doesn't change combination of members. If you are using an array, there is a sort function.

This article has been dead for over six months. Start a new discussion instead.