Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Combo Box Neues Item (https://www.delphipraxis.net/12853-combo-box-neues-item.html)

citybreaker 5. Dez 2003 09:53


Combo Box Neues Item
 
Hallo,
ich will bei der ComboBox ein Item hinzufügen.
Alerdings soll es nur hinzugefügt werden wenn
es noch kein anderes Item mit dem selben Namen
besteht. Hab alerdings keine Idee wie ich das anstellen
soll. :roll:

sakura 5. Dez 2003 09:59

Re: Combo Box Neues Item
 
Sagen wir mal, daß in strItem Dein neuer Wert ist, dann:

Delphi-Quellcode:
if ComboBox1.Items.IndexOf(strItem) < 0 then
  ComboBox1.Items.Add(strItem);
...:cat:...

choose 5. Dez 2003 09:59

Re: Combo Box Neues Item
 
Hallo citybreaker,

sieh mal in der OH bei TStrings unter der Methode IndexOf nach. Mithilfe dieser Methode kannst Du testen, ob in einer Liste von Strings (einem Exemplar der abstrakten(!) Klasse TStrings oder einem Erben, also zB auch TComobox.Items), ein String bereits vorhanden ist (Rückgabewert in der OH beachten).


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:11 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