Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Text aus Listbox in Label (https://www.delphipraxis.net/33470-text-aus-listbox-label.html)

Superior 7. Nov 2004 18:52


Text aus Listbox in Label
 
Hallo,

ich suche einen Befehl für folgendes:
Ich habe eine Listbox mit vielen Items. Ich will jetzt eine beliebige Zeile (beispielsweise die 3. Zeile) in ein Label kopieren.
Wie geht das? Könnte mir da jemand den Befehl für nennen?

Vielen Dank schon einmla im Vorraus.

mfg
Superior

Die Muhkuh 7. Nov 2004 18:54

Re: Text aus Listbox in Label
 
Hi,

Delphi-Quellcode:
procedure {OnClick der Listbox}
begin
  Label1.Caption := ListBox1.Items.Strings[ListBox1.ItemIndex]
end;
*MFG*

Manu :hi:

mirage228 7. Nov 2004 18:55

Re: Text aus Listbox in Label
 
Hi,

da die Items der ListBox 0-basiert sind, heisst das, dass die 3. Zeile den Index = 2 hat, daher:
Delphi-Quellcode:
// aktuell ausgewählte zeile darstellen (<- ins OnClick der ListBox damit):
if ListBox1.ItemIndex > -1 then
  Label1.Caption := ListBox1.Items[ListBox1.ItemIndex];
// explizit das 3. item
  Label1.Caption := ListBox1.Items[2];
Ich hoffe das hilft Dir weiter :)

mfG
mirage228

mirage228 7. Nov 2004 18:56

Re: Text aus Listbox in Label
 
Zitat:

Zitat von Spider
Hi,

Delphi-Quellcode:
procedure {OnClick der Listbox}
begin
  Label1.Caption := ListBox1.Items.Strings[ListBox1.ItemIndex]
end;
*MFG*

Manu :hi:

Und wenn nichts gewählt und der Index daher = -1? :mrgreen:

Also vorher abfragen:
Delphi-Quellcode:
  if ListBox1.ItemIndex > -1 then
    Label1.Caption := ListBox1.Items[ListBox1.ItemIndex]
mfG
mirage228

Die Muhkuh 7. Nov 2004 18:58

Re: Text aus Listbox in Label
 
Meine Güte,

er wird ja wohl selbst denken können oder :zwinker:

Superior 7. Nov 2004 20:00

Re: Text aus Listbox in Label
 
Ja super vielen Dank.

Es klappt.

mfg
Superior


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:53 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz