Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi ComboBox1.Itemindex (https://www.delphipraxis.net/10859-combobox1-itemindex.html)

horst 26. Okt 2003 22:00


ComboBox1.Itemindex
 
hallo
habe auf form2 ein edit, in dieses edit gebe ich ein wort ein...
alles wird in einer datei gespeichert
mein problem ist eine combobox auf form1, die items werden mit
Delphi-Quellcode:
with ComboBox1 do
begin
  Items.LoadFromFile(extractfilepath(application.exename)+ 'themen\themen.txt');
aus einer textdatei gefüllt.
nun zu meiner frage:
ich möchte, das in form2.edit eingegebene wort in der combobox auf form1 zu sehen ist.
quasi als Form1.ComboBox1.Itemindex

Delphi-Quellcode:
procedure TForm2.Button1Click(Sender: TObject);
Var
  I : Integer;
  F : TextFile;
  temp:string;
Begin
   memo1.lines.loadfromfile(extractfilepath(application.exename)+ 'themen\themen.txt');
   memo1.lines.add(edit1.text);
   createDir(extractfilepath(application.exename)+ 'themen\'+''+edit1.Text+'');
   memo1.lines.savetofile(extractfilepath(application.exename)+ 'themen\themen.txt');
   memo1.clear;
   close;
   Form1.ComboBox1.Items.LoadFromFile(extractfilepath(application.exename)+ 'themen\themen.thm');
   Form1.ComboBox1.Itemindex:=edit1.Text; // <----das ist mein problem
End;

Jelly 26. Okt 2003 22:06

Re: ComboBox1.Itemindex
 
Zitat:

Zitat von horst
Delphi-Quellcode:
   Form1.ComboBox1.Itemindex:=edit1.Text; // <----das ist mein problem

Ersetze die Zeile durch
Delphi-Quellcode:
form1.combobox1.itemindex := form1.combobox1.items.indexof (edit1.text) ;
Gruß,
Tom

Christian Seehase 26. Okt 2003 22:07

Re: ComboBox1.Itemindex
 
Moin Horst,

meinst Du das:

Delphi-Quellcode:
// Zeile hinzufügen
Form1.ComboBox1.Items.Add(Form2.edit1.Text);
// und diese dann im Editfeld der ComboBox anzeigen
// (Items.Count-1) = Index des letzten Items
Form1.ComboBox1.ItemIndex := Form1.ComboBox1.Items.Count-1;
?

horst 26. Okt 2003 22:16

Re: ComboBox1.Itemindex
 
hallo christian

itemindex soll sein: das wort welches vorher in form2.edit1 eingegeben wurde.
dein beispiel gibt ja den letzten eintrag zurück, wäre ja auch schon fast richtig
nur habe ich die combobox auf sorted=true...
dann haut das nicht mehr hin
Delphi-Quellcode:
  Form1.ComboBox1.ItemIndex := Form1.ComboBox1.Items.Count-1;
wenn das nicht anders geht dann mache ich es so wie du es geschrieben hast...
merci ;)

obwohl, wenn ich bedenke, die textdatei ist auch nicht sortiert.

horst 26. Okt 2003 22:20

Re: ComboBox1.Itemindex
 
Delphi-Quellcode:
form1.combobox1.itemindex := form1.combobox1.items.indexof (edit1.text) ;
das funktioniert supi ;)


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