Solved

Add items to TListBox in REVERSE order

Posted on 1998-10-09
4
390 Views
Last Modified: 2011-09-20
I know that to add an item to a TListBox, one simply uses...

ListBox1.Items.Add(Edit1.Text);

However, this adds the new item to the END of the list.  What I am trying to accomplish is to place the new item at the BEGINNING of the list.

IOW, I would like to see this...

ListBox1.Items.Add('1');
ListBox1.Items.Add('2');
ListBox1.Items.Add('3');

...result in the following display in the ListBox...

3
2
1

...instead of the current behavior, which gives me...

1
2
3

What is the best way to accomplish this reverse order?
0
Comment
Question by:Softtech
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
ow earned 80 total points
ID: 1342380
Hi softtech,

you may use a seperate stringlist first, where you can insert strings at any positon.
Then deliver it to the listbox:

var
  StringList :tStringlist;
  Listbox1 :tListBox;
.
StringList.Insert(0, '1');
StringList.Insert(0, '2');
StringList.Insert(0, '3');
.
ListBox1.Items := StringList;

regards
  ow
0
 
LVL 1

Expert Comment

by:borup
ID: 1342381
Nice solution ;-)
0
 

Author Comment

by:Softtech
ID: 1342382
I still have to .Create and .Free the TStringList, don't I?

Out of curiousity, if I wanted to have take the contents of the StringList, and have it fill the TListBox, would I simply do this?...

MyStringList := TStringList.Create;
.
.
ListBox1.Items.Assign(MyStringList)

???
0
 
LVL 1

Expert Comment

by:ow
ID: 1342383
Softtech,

you are right at all.
You must create and free the stringlist and you can use either "ListBox.Items.Assign(StringList)" or "ListBox.Items := StringList".
Items.Assign is just the method, which is called, when you write to property tListbox.Items.

regards
  ow
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question