Autor Beitrag
110022
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Mi 19.12.07 16:02 
wie entferne ich mit nem edit feld nen listbox eintrag??
Das habe ich schon:
ausblenden Delphi-Quelltext
1:
listbox1.items.delete(edit1.text);					

aber das klappt nicht
wie gehts denn richtig
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Mi 19.12.07 16:06 
(a) die Suche hier benutzen
(b) listBox.Delete + F1
(c) oder so
ausblenden Delphi-Quelltext
1:
2:
    
listbox1.items.delete(ListBox1.Items.indexOf(edit1.text));

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Mi 19.12.07 17:41 
Den Code von Kroko würde ich noch um eine Prüfung erweitern:
ausblenden Delphi-Quelltext
1:
2:
if ListBox1.Items.indexOf(edit1.text) > -1 then
  listbox1.items.delete(ListBox1.Items.indexOf(edit1.text));


Lg, Martin

_________________
Ein Nutzer der Ecke ;-)
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 19.12.07 17:50 
Prüfung ist gut, aber hier wird die Listbox 2 mal durchsucht, was eher suboptimal ist.
Daher: Ergebnis von IndexOf zwischenspeichern.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mi 19.12.07 18:13 
user profile iconjakobwenzel hat folgendes geschrieben:
Prüfung ist gut, aber hier wird die Listbox 2 mal durchsucht, was eher suboptimal ist.
Daher: Ergebnis von IndexOf zwischenspeichern.

Man kann es auch übertreiben! Wenn du eine 2GB große Liste hast, wirkt es sich vielleicht aus, aber so wie es aussieht, Wird der Code einmal pro Buttonklick ausgeführt, und die Liste wird auch keine Gigabyte groß sein.
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Do 20.12.07 11:01 
user profile iconYogu hat folgendes geschrieben:
Man kann es auch übertreiben!

Das war auch mein erste Gedanke. ;-)

_________________
Ein Nutzer der Ecke ;-)
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 20.12.07 11:43 
user profile iconMartin1966 hat folgendes geschrieben:
user profile iconYogu hat folgendes geschrieben:
Man kann es auch übertreiben!

Das war auch mein erste Gedanke. ;-)

nein kann man nicht, wer klein so anfängt wird es immer so machen und bekommt vielleicht ne anstellung bei MS(siehe windoofs), wird aber kein guter Progger!

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Do 20.12.07 11:49 
oder vllt hilft dir TListBox.DeleteSelected -> löscht alle markierten Einträge.
.#R4id
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

Windows XP Prof.
CodeGear Delphi 2007
BeitragVerfasst: Do 20.12.07 18:09 
Wie wollt ihr das Regeln, wenn es zwei mal den selben Eintrag gibt?

_________________
ausblenden Delphi-Quelltext
1:
if CopyAndPaste not avaible then Developer := Helpless;					
LorenzS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
BeitragVerfasst: Do 20.12.07 18:29 
So:
ausblenden Delphi-Quelltext
1:
2:
While ListBox1.Items.indexOf(edit1.text) > -1 do 
  listbox1.items.delete(ListBox1.Items.indexOf(edit1.text));


Und für GByte Anwendungen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
 Var Index:Integer;

 Index:=ListBox1.Items.indexOf(edit1.text);
 While I > -1 do 
 begin
  Listbox1.items.delete(Index);
  Index:=ListBox1.Items.indexOf(edit1.text);
 end;