Solved

Add items to TListBox in REVERSE order

Posted on 1998-10-09
4
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

688 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