Autor Beitrag
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 20.12.07 15:46 
Mit listBox1.Items.IndexOf(deinString) den passenden Index suchen. Diesen Index der listBox1.ItemIndex-Eigenschaft zuweisen.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
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 15:54 
Zitat:
dann kommen aber 2 fehler
ausblenden Delphi-Quelltext
1:
2:
3:
  
[Fehler] Unit1.pas(33): Operator oder Semikolon fehlt
[Fehler] Unit1.pas(34): Operator oder Semikolon fehlt

wie is das richtig?


Es wäre noch praktisch wenn uns zeile 33 und 34 explizit kopierst!
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Do 20.12.07 16:08 
zeile 33 =if ListBox1.ItemIndex(w) >= 0 then
zeile 34 =ListBox1.ItemIndex := ListBox1.ItemIndex(w);
die meldungen kennt ihrt ja schon
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 20.12.07 17:04 
...
Was ist "w" ? Verwechselst du ItemIndex eventuell mit IndexOf ?
Schau dir doch nun endlich mal die Beschreibung zu diesen Befehlen an!! Markieren + F1.

cu
Marc
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 17:27 
user profile iconYogu Verfasst am: Mi 19.12.07 17:37 hat folgendes geschrieben:
Folgender Code reicht doch vollkommen aus:

ausblenden Delphi-Quelltext
1:
2:
if ListBox.ItemIndex(String) >= 0 then
  ListBox.ItemIndex := ListBox.ItemIndex(String);

Alle anderen Lösungen sind eigentlich unnötig kompliziert.

Da hat er es her!

1. Exacte Suche
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button10Click(Sender: TObject);
begin
 if ListBox1.Items.IndexOf(trim(Edit1.text))>=0 then //ListBox interne Suchsunktion IndexOf
                                                     //Trim ist nicht unbedingt nötig lösche aber hinten und vorne alle Leerzeichen
  ListBox1.ItemIndex:=ListBox1.Items.IndexOf(trim(Edit1.text));
end;

2. Ungenaue Suche (im EditFeld reicht schon ein Teil um die Einträge in der ListBox zufinden)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button10Click(Sender: TObject);
 var i:integer
begin
 for i:=0 to listbox1.items.count-1 do
  if pos(edit1.Text, listbox1.items[i]) > 0 then
   listbox1.itemindex:=i; 
end;

3. Kombi aus beidem, wenn er das Exacte nicht findet, versucht er es ungenau
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button10Click(Sender: TObject);
 var i:integer
begin
 if ListBox1.Items.IndexOf(trim(Edit1.text))>=0 then //ListBox interne Suchsunktion IndexOf
                                                     //Trim ist nicht unbedingt nötig lösche aber hinten und vorne alle Leerzeichen
  ListBox1.ItemIndex:=ListBox1.Items.IndexOf(trim(Edit1.text))
 else
  for i:=0 to listbox1.items.count-1 do
   if pos(edit1.Text, listbox1.items[i]) > 0 then
    listbox1.itemindex:=i; 
end;
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: Do 20.12.07 17:37 
user profile iconYogu am Mi 19.12.07 17:37 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
if ListBox.ItemIndex(String) >= 0 then
  ListBox.ItemIndex := ListBox.ItemIndex(String);

Oh, großes Sorry! Da habe ich wohl etwas durch einander gebracht. :oops: So müsste es eigentlich heißen:
ausblenden Delphi-Quelltext
1:
2:
if ListBox.IndexOf(String) >= 0 then
  ListBox.ItemIndex := ListBox.IndexOf(String);


:autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: