Board index » delphi » listbox problem (newbie)

listbox problem (newbie)

Hi,
a textfile is being opend in my program
Each line from the textfile is read and putted in a listbox :
(each line in the textfile represent a path (C:\Mypath\my.exe) to another
file)
the total lines in the textfile are not constant
( in one file it may be 30 lines and in an other it may be 50 lines)
1 line (in the textfile) = 1 item(in the listbox)
now, when i doubleklik on an item in the listbox( has just been
filled with lines from the textfile), the text
 that's in that item must be read and send as a caption
too a label on the form, how is this posible?

Please help me,

Vincent
vi...@pi.be

 

Re:listbox problem (newbie)


Quote
>the text
> that's in that item must be read and send as a caption
>too a label on the form, how is this posible?

In the double-click event:

if ListBox1.ItemIndex > -1 then
  Label1.Caption := ListBox1.Items[ListBox1.ItemIndex]
  else Label1.Caption := '';

Chris

Re:listbox problem (newbie)


A previous poster answered your question. I just wanted to point out that
you don't need to read each line of the textfile and add it to the listbox.
Instead use

aListBox.Items.LoadFromFile (theTextFileName);

to load the entire file into the list box.

Quote
Vincent Vijt <vi...@planetinternet.be> wrote in message

news:7t39uh$ebn$1@news.planetinternet.be...
Quote
> Hi,
> a textfile is being opend in my program
> Each line from the textfile is read and putted in a listbox :
> (each line in the textfile represent a path (C:\Mypath\my.exe) to another
> file)
> the total lines in the textfile are not constant
> ( in one file it may be 30 lines and in an other it may be 50 lines)
> 1 line (in the textfile) = 1 item(in the listbox)
> now, when i doubleklik on an item in the listbox( has just been
> filled with lines from the textfile), the text
>  that's in that item must be read and send as a caption
> too a label on the form, how is this posible?

> Please help me,

> Vincent
> vi...@pi.be

Re:listbox problem (newbie)


Hi!

To fill the listbox with the textfile:

procedure TForm1.Button1Click(Sender: TObject);
begin
 ListBox1.Items.LoadFromFile('MyFile.txt');
end;

To transfer the listitem to a label:

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
    Label1.caption:=listbox1.items[listbox1.itemindex];
end;

Hope this helps!

best regards,
Geir Bratlie

Vincent Vijt <vi...@planetinternet.be> skrev i
meldingsnyheter:7t39uh$eb...@news.planetinternet.be...

Quote
> Hi,
> a textfile is being opend in my program
> Each line from the textfile is read and putted in a listbox :
> (each line in the textfile represent a path (C:\Mypath\my.exe) to another
> file)
> the total lines in the textfile are not constant
> ( in one file it may be 30 lines and in an other it may be 50 lines)
> 1 line (in the textfile) = 1 item(in the listbox)
> now, when i doubleklik on an item in the listbox( has just been
> filled with lines from the textfile), the text
>  that's in that item must be read and send as a caption
> too a label on the form, how is this posible?

> Please help me,

> Vincent
> vi...@pi.be

Other Threads