954,202 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VB.Net Combobox Reverse Order

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?...

ScatterMap
Newbie Poster
2 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

Yes it is possible.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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.

hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You