Autor Beitrag
Jagg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mo 03.11.03 21:19 
Hallo Leute !
Wie suche ich einen text in einer ListBox und dann soll der Text makiert werden !
geht das mit setfocus ???

Jagg !
Pascal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155

Win 98, Win XP
Delphi 2005, Delphi 5
BeitragVerfasst: Mo 03.11.03 22:03 
Also um in einer Listbox ein item zu markieren muss man Listboxy.itemindex:=n-1;
einsetzen
mit dem suchen schau ich noch mal nach
Pascal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155

Win 98, Win XP
Delphi 2005, Delphi 5
BeitragVerfasst: Mo 03.11.03 22:16 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function sucheTextinListe(Text:String;Liste:Titems):integer;
begin
 result:=-1;
 for t:=0 to Liste.count-1 do
  if Text=Liste[t] then begin
   result:=t;
   exit;
  end;
end;


und aufgerufen z.B. so
ausblenden Delphi-Quelltext
1:
Listbox1.itemindex:=SuchetextinListe('Hallo',Listbox1.items);					


müsste gehen (ist aber ungetestet); mit Listbox1.setfocus makierst du die Listbox

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Di 04.11.03 10:07 
Pascal hat folgendes geschrieben:
mit dem suchen schau ich noch mal nach

Wie wäre es mit IndexOf?

Also:
ausblenden Delphi-Quelltext
1:
ListBox1.ItemIndex := ListBox1.Items.IndexOf ('Text');					

Gruß
Tino

PS: @Pascal: Was ist denn Titems für ein Type? Hätte da nicht TStrings benutzt werden müssen?
Pascal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155

Win 98, Win XP
Delphi 2005, Delphi 5
BeitragVerfasst: Di 04.11.03 18:05 
äh ja Tstrings meinte ich eigentlich...

Indexof kannte ich nicht, meine Methode habe ich mal in einem Buch gelesen, die scheinen es wohl auch nicht gekannt zu haben.
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Di 04.11.03 20:20 
kann man eigentlich mit einer listbox auch FILTERN ????
wenn ja wie denn ?
mit listbox1.filter ???
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Di 04.11.03 20:50 
ich habe mit dem code von tino versucht das geht nicht
ich bekomme nicht hindas er den geuschten text markiert
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Di 04.11.03 22:11 
Dir ist aber klar, das du mit den beiden gezeigten Methoden keinen "Text" im eigentlichen Sinne suchen kannst, sondem nur nach kompleten Einträgen.
z.B. Listbox eintrag: "dies ist ein Test", würde dir die Suche nach Test in beiden Fällen kein item markieren werden.
Hauptunterschied zwischen indexof und Text=Liste[t] ist das bei indexof die Großkleinschreibung egal ist.

Wenn du teilstrings suchst, muß du die einzelnen items mit pos abklappern.

oder wo genau liegt jetzt dein Problem? sonst poste ein kleines beispiel deiner Liste und wo nach du suchst.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)