Autor Beitrag
n0name
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 11.05.04 09:28 
Hi I need to create function that will search subitem in a column in ListView2 and show this subitem (with all other subitems in this line) in the ListView1. I've got something like that, but i doesn't work:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
procedure TForm8.SpeedButton1Click(Sender: TObject); 
Var 
i: Integer; 
ListItem: TListItem; 

begin 
MaInForm.ListView2.Visible := False; 
MaInForm.ListView1.Visible := True; 
for i := MaInForm.ListView2.ItemIndex+1 to MaInForm.ListView2.Items.Count - 1 do 
if Pos((Edit2.Text),(MaInForm.ListView2.Items[i].SubItems[0])) > 0 then 

begin with MainForm do 
if ListView2.SelCount = 1 then//==== jeśli zaznaczone 
begin 
ListItem := ListView1.Items.Add; 
ListItem.Caption:= ListView1.Selected.Caption; 
ListItem.SubItems.Add ( ListView2.Selected.SubItems[0]); 
ListItem.SubItems.Add ( ListView2.Selected.SubItems[1]); 
ListItem.SubItems.Add ( ListView2.Selected.SubItems[2]); 
ListItem.SubItems.Add ( ListView2.Selected.SubItems[3]); 
ListItem.SubItems.Add ( ListView2.Selected.SubItems[4]); 
end; 
end; 
end;


Can someone help me?

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
Alexander F
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 149

Win XP, Win 2000
D6 PE, D7 Prof, D8 Prof
BeitragVerfasst: Di 11.05.04 10:48 
Hi,
I hope this sample can help:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
Var
 i : Integer;
 ListItem: TListItem;
begin
 for i:=0 to ListView2.Items.Count -1 do
  begin
    if (ListView2.Items.Item[i].SubItems.IndexOf(Edit1.Text) > -1) then
        ListView1.Items.AddItem(ListView2.Items.Item[i], -1);
  end;
end;

The string edit1.text will be searched in Listview2 in all SubItems. When it was found, it will be added to Listview1.
I have not tested it... So I hope it will work ;-)
n0name Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 11.05.04 11:06 
Thx.... :D
n0name Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 11.05.04 13:22 
Hmmm there's only one problem when later i Clear ListView1 SubItem, in ListView2 this subitem is cleared too :?