Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Markiertes Listbox Item nach Edit (https://www.delphipraxis.net/41577-markiertes-listbox-item-nach-edit.html)

sandraeberlein 5. Mär 2005 14:24


Markiertes Listbox Item nach Edit
 
Ich probiere es ständig so:

Code:
listbox1.items[0] := edit1.text;
Aber wie geht das mit einem Markiertem Item?

danke und Bussi :love: sandra

Luckie 5. Mär 2005 14:29

Re: Markiertes Listbox Item nach Edit
 
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  s: String;
begin
  for i := 0 to Listbox1.Items.Count - 1 do
  begin
    if Listbox1.Selected[i] then
      s := Listbox1.Items[Listbox1.ItemIndex];
  end;
  ShowMessage(s);
end;
Aber ein Blick in die Hilfe hätte es auch getan. :roll:

Die Muhkuh 5. Mär 2005 14:39

Re: Markiertes Listbox Item nach Edit
 
@Luckie

warum so umständlich:

[delphi]var
S: String;
begin
S := ListBox1.Items.Strings[ListBox1.ItemIndex];
Edit1.Text := S;
end;

mirage228 5. Mär 2005 14:45

Re: Markiertes Listbox Item nach Edit
 
Zitat:

Zitat von Spider
@Luckie

warum so umständlich:

Delphi-Quellcode:
var
  S: String;
begin
  S := ListBox1.Items.Strings[ListBox1.ItemIndex];
  Edit1.Text := S;
end;

@Spider

Warum so umständlich (und auch noch ohne Fehlerbehandlung) ? :mrgreen:

Delphi-Quellcode:
if ListBox1.ItemIndex <> -1 then
  Edit1.Text := ListBox1.Items[ListBox1.ItemIndex];
/// ----- oder ------
with ListBox1 do
  if ItemIndex <> -1 then
    Edit1.Text := Items[ItemIndex];
mfG
mirage228

Die Muhkuh 5. Mär 2005 14:48

Re: Markiertes Listbox Item nach Edit
 
Zitat:

Zitat von mirage228
Zitat:

Zitat von Spider
@Luckie

warum so umständlich:

Delphi-Quellcode:
var
  S: String;
begin
  S := ListBox1.Items.Strings[ListBox1.ItemIndex];
  Edit1.Text := S;
end;

@Spider

Warum so umständlich (und auch noch ohne Fehlerbehandlung) ? :mrgreen:

Delphi-Quellcode:
if ListBox1.ItemIndex <> -1 then
  ListBox1.Items[ListBox1.ItemIndex] := Edit1.Text;
/// ----- oder ------
with ListBox1 do
  if ItemIndex <> -1 then
    Items[ItemIndex] := Edit1.Text;
[i]Edit: Wieso zur Hölle werden meine Delphi Codes nicht übernommen?

Warum machst du das falsch rum? Sie will das markierte ins Edit machen:

Delphi-Quellcode:
if ListBox1.ItemIndex <> -1 then
  Edit1.Text := ListBox1.Items[ListBox1.Itemindex];

mirage228 5. Mär 2005 14:52

Re: Markiertes Listbox Item nach Edit
 
Ups, hab mir jetzt nur den Code oben durchgelesen. Dann muss es natürlich nur andersrum sein.

mfG
mirage228

lblbw 15. Aug 2005 21:01

Re: Markiertes Listbox Item nach Edit
 
Habe diesen Code genommen, aber wenn ich nun auf den button klicke, passiert gar nichts.

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to Listbox1.Items.Count - 1 do
  begin
    if Listbox1.Selected[i] then
      Edit2.Text := Listbox1.Items[Listbox1.ItemIndex];
  end;
end;

fkerber 15. Aug 2005 21:05

Re: Markiertes Listbox Item nach Edit
 
Hi!

Sicher, dass der Code aufgerufen wird?

Ciao Frederic

Sharky 15. Aug 2005 21:06

Re: Markiertes Listbox Item nach Edit
 
Was möchtest Du denn genau machen?
Dein Code gilt ja (allerdings mit fehler) für eine ListBox mit MultiSelect.
Wenn Du "nur" das selektierte Item im Edit haben möchtest dann :

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
   Edit2.Text := Listbox1.Items[Listbox1.ItemIndex];
end;


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

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