How do i reverse the order of a combobox. I'm currently loading cboItems.items.add (reader.readline) from a .txt document using streamreader.

After the items are loaded into the Combobox, i want to reverse their order from Bottom to Top.

Is that possible?...

Recommended Answers

All 2 Replies

Member Avatar for iamthwee

Yes it is possible.

Use an ArrayList, then iterate backwards

using System;
using System.Collections;
using System.IO;

namespace SortedList
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList stringList = new ArrayList();

            StreamReader stringReader = new StreamReader("c:\\OptionList.txt");
            string option = "";

            while ((option = stringReader.ReadLine()) != null)
            {
                stringList.Add(option);
            }

            stringReader.Close();
            stringReader.Dispose();

            stringList.TrimToSize();

            for (int i = stringList.Count - 1; i >= 0; --i)
            {
                Console.WriteLine(stringList[i]);
            }

            Console.ReadLine();
        }
    }
}

You'll have to translate to VB syntax cos I can't stand VB syntax it makes my teeth jangle! And besides gotta leave you with something to do.

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.