Board index » delphi » Help list box

Help list box

Need help on some of the following :

I have a list box and the items are added/removed using two buttons 'Add'
and 'Remove'.  The problem is that when an item is added, it should
appear right on top of the list box and not after the last element
entered.  The same goes for the 'Remove' button.  Each element to be
deleted is to be removed from the top onwards.  The element is of string
type.

Thank you so very much as I need to do this pretty soon or else my brain
will go cold soon...................

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet

 

Re:Help list box


Quote
mcai5...@ist4.co.umist.ac.uk wrote:

> Need help on some of the following :

> I have a list box and the items are added/removed using two buttons 'Add'
> and 'Remove'.  The problem is that when an item is added, it should
> appear right on top of the list box and not after the last element
> entered.  The same goes for the 'Remove' button.  Each element to be
> deleted is to be removed from the top onwards.  The element is of string
> type.

        Well, for the insert you could use the Insert method:

procedure TForm1.Button1Click(Sender: TObject);
const j: integer = 0;
begin
  ListBox1.Items.Insert(0, IntToStr(j));
  inc(j);
end;

        On give-a-man-a-fish versus teach-a-man-to-fish grounds I'm
just going to give you a hint on deleting the item: TListBox.Items
is of type TStrings, and you can find a way to delete the first
item in the docs under TStrings.

--
David Ullrich

sig.txt not found

Re:Help list box


Simple.

First, make sure your listbox's Sorted property is set to False.
Then, to add an item to the top of the list, use:

     ListBox1.Items.Insert(0, 'TopItem');

Then, to delete an item from the top of the list, use:

     ListBox1.Items.Delete(0);

My guess is that you're currently using the Add and Remove methods
which automatically Add and Remove to the end of the list, rather
than from any indexed location.

Hope this helps,
-Jim Rofkar.

Re:Help list box


the strings in a listbox are tstrings (the items property of the box).

tstrings has an insert method in addition to add which takes an index and a
string value as parameters.  Use this with index = 0 to insert at the top of
the list.

Hope this helps.

Max

                  ///
                / ^ \         Downey Communications Inc.
               ( o-o )        Programmer/Analyst
---oOOO--(_)--OOOo------------------------------------------
    .oooO               'OOPS...Was that your foot?'
    (   )   Oooo.
-----\ (----(   ) ------------------------------------------
      \_)    ) /
            (_/     Allen A. Maxwell
        email:      aa...@sprynet.com
        snail Mail: 649 Hollywood Ave.
                    Salt Lake City, Ut. 84105
        voice:      801 486-7208

Quote
mcai5...@ist4.co.umist.ac.uk wrote in message

<878259865.16...@dejanews.com>...
Quote
>Need help on some of the following :

>I have a list box and the items are added/removed using two buttons 'Add'
>and 'Remove'.  The problem is that when an item is added, it should
>appear right on top of the list box and not after the last element
>entered.  The same goes for the 'Remove' button.  Each element to be
>deleted is to be removed from the top onwards. The element is of string
>type.

>Thank you so very much as I need to do this pretty soon or else my brain
>will go cold soon...................

>-------------------==== Posted via Deja News ====-----------------------
>      http://www.dejanews.com/     Search, Read, Post to Usenet

Other Threads