Softtech
asked on
Add items to TListBox in REVERSE order
I know that to add an item to a TListBox, one simply uses...
ListBox1.Items.Add(Edit1.T ext);
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?
ListBox1.Items.Add(Edit1.T
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nice solution ;-)
ASKER
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(MySt ringList)
???
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(MySt
???
Softtech,
you are right at all.
You must create and free the stringlist and you can use either "ListBox.Items.Assign(Stri ngList)" or "ListBox.Items := StringList".
Items.Assign is just the method, which is called, when you write to property tListbox.Items.
regards
ow
you are right at all.
You must create and free the stringlist and you can use either "ListBox.Items.Assign(Stri
Items.Assign is just the method, which is called, when you write to property tListbox.Items.
regards
ow