Board index » delphi » Copying from listbox1 to listbox2

Copying from listbox1 to listbox2

I want all the data that is in a listbox on form1 copied to a listbox on
form2. How can i do that?

Greets,

Ben van Erp
bv...@usa.net

 

Re:Copying from listbox1 to listbox2


form1.listbox1.items.AddStrings(form2.listbox2.Items);
Quote
B <bv...@usa.net> wrote in message news:7fa54a$4ch$1@news.worldonline.nl...
> I want all the data that is in a listbox on form1 copied to a listbox on
> form2. How can i do that?

> Greets,

> Ben van Erp
> bv...@usa.net

Re:Copying from listbox1 to listbox2


Quote
In article <7fa54a$4c...@news.worldonline.nl>, "B" <bv...@usa.net> writes:
>I want all the data that is in a listbox on form1 copied to a listbox on
>form2. How can i do that?

Form2.ListBox2.Items.Assign(Form1.ListBox1.Items);

AddStrings appends the strings to those existing (if any), Assign replaces
them.

Alan Lloyd
alangll...@aol.com

Re:Copying from listbox1 to listbox2


listbox2.items.assign(listbox1.items);

--

Craig Edgar
Managing Director
ACTCASE PTY. LTD.

Visit us at http://www.actcase.com/index.htm
Send your E-mail to mana...@actcase.com
ICQ UIN 2539645 when I remember to load it
Phone 61+ 0418-247808

Quote
B <bv...@usa.net> wrote in message news:7fa54a$4ch$1@news.worldonline.nl...
> I want all the data that is in a listbox on form1 copied to a listbox on
> form2. How can i do that?

> Greets,

> Ben van Erp
> bv...@usa.net

Re:Copying from listbox1 to listbox2


Quote
On Sat, 17 Apr 1999 16:16:08 +0200, "B" <bv...@usa.net> wrote:
>I want all the data that is in a listbox on form1 copied to a listbox on
>form2. How can i do that?

One way is with a single command line using the Assign method of string
list objects (of which the TListBox.Items property is one).

  ListBox2.Items.Assign(ListBox1.Items);

This copies the items from ListBox1 to ListBox2, but entirely replaces what
was in ListBox2 before that.

To make the copying cumulative, base a loop on the TListBox.Items.Count
property and in that loop traverse each item in the source TListBox. At
each item, call the TListBox.Items.Add method to add it to the destination
list box. Something like:

  for i := 0 to (ListBox1.Items.Count - 1) do
    ListBox2.Items.Add(ListBox1.Items[i]);

//////////////////////////////////////////////////////////////////////////
Steve Koterski                   "There are two kinds of pedestrians...the
Technical Publications           quick and the dead."
INPRISE Corporation                            -- Lord Thomas Robert Dewar
http://www.borland.com/delphi                                  (1864-1930)

Other Threads