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.

please code for assorting information in listbox in c#.
by
shihab

my friend just use
select * from tablename group by Columname;
regards..
Farhad

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()
        {
            InitializeComponent();
            string[] array = new string[] { "D", "C", "A", "E", "B" };
            Array.Sort(array);
            listBox1.Items.AddRange(array);
        }

        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();
            }
            Array.Reverse(array);
            listBox1.Items.Clear();
            listBox1.Items.AddRange(array);

        }

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.