Autor Beitrag
ralfi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 153



BeitragVerfasst: Fr 04.07.03 13:31 
Hallo
ich habe ein ListView mit mehreren Items.
ViewStyle := vsReport
RowSelect := True
In einem der Items befindet sich ein String. Wie kann ich der Index des Items in dem sich der String befindet rausfinden, ohne das der Item markiert (ItemIndex) wird?
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Fr 04.07.03 13:51 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function findListViewItem(Str:String):integer;   
begin
  result:=-1
  for i:=0 to ListView1.Items.Count-1 do begin
    if ListView1.Items[i].Caption = Str then begin
      result:=i;
      exit;
    end;
  end;
end;

weiß nicht ob es funktioniert, da ich es ebend schnell aus dem kopf geschrieben habe.

_________________
MFG
Michael Springwald, "kann kein englisch...."
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Fr 04.07.03 13:55 
Hi,

das geht so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TfrmMain.Button1Click(Sender: TObject);
var
 i: Integer;
begin
  for i := 0 to ListView1.Items.Count - 1 do
   if ListView1.Items[i].Caption = 'MeinString' then
     caption := IntToStr(i);
end;


MFG

- Ernesto -

// Edit: zu langsam
@mimi: Zählervariablen sollten lokal sein
ralfi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 153



BeitragVerfasst: Fr 04.07.03 14:15 
Danke!!! :)
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: Fr 04.07.03 14:20 
Hallo, wenn nur darum geht, eine Caption zu finden, würd ich die Methoden verwenden, die das Listview schon mitbringt, z.B. Findcaption . Das bringt mehr Möglichkeiten und kein Problem mit Groß- und Kleinschreibung.
Für die Subitems gibts die Möglichkeit mit Indexof bei Tstrings zu suchen.

Mfg Frank

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