Autor Beitrag
Stoffel1984
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: Mo 07.07.03 10:55 
Hallo,

ich möchte eine ListView mit allen ausgewählten Items (checked) in eine andere ListView kopieren. Mit den Items an sich klappt es. Nur die SubItems machen mir noch etwas Probleme.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Verarbeiten;
var
  i : integer;
begin
  for i:=0 to Form1.Listview1.Items.Count-1 do
  begin
    if Listview1.Items[i].Checked then
    begin
      Listview2.AddItem(Listview1.Items[i].Caption, Self);
    end;
  end;
end;


Weis jemand wie ich das hinbekomme?

Danke im vorraus,

Stoffel
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: Mo 07.07.03 11:38 
Hallo Stoffel,

z.B. so:

ausblenden volle Höhe 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:
25:
26:
27:
28:
29:
30:
31:
32:
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;           //ListView füllen
begin
  ListView1.AddItem('A', self);
  ListView1.AddItem('B', self);
  ListView1.AddItem('C', self);
  ListView1.AddItem('D', self);
  ListView1.AddItem('E', self);

  for i := 0 to ListView1.Columns.Count - 1 do
  begin
    ListView1.Items[0].SubItems.Add('A' + IntToStr(i));
    ListView1.Items[1].SubItems.Add('B' + IntToStr(i));
    ListView1.Items[2].SubItems.Add('C' + IntToStr(i));
    ListView1.Items[3].SubItems.Add('D' + IntToStr(i));
    ListView1.Items[4].SubItems.Add('E' + IntToStr(i));
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i, j: Integer;          //ListView1 in ListView2 kopieren
begin
  for i := 0 to ListView1.Items.Count - 1 do
    if ListView1.Items[i].Checked then
      ListView2.AddItem(ListView1.Items[i].Caption, self);

  for i := 0 to ListView2.Items.Count - 1 do
    for j := 0 to ListView2.Columns.Count - 1 do
      ListView2.Items[i].SubItems.Add(ListView1.Items[i].SubItems[j]);
end;


MFG

- Ernesto -
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 07.07.03 12:14 
Oder so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  i  : integer;
  li : TListItem;
begin
  lv2.Items.Clear;
  lv2.Items.BeginUpdate;

  with lv1 do
    for i := 0 to Items.Count - 1 do
      if(Items[i].Checked) then begin
        li          := lv2.Items.Add;
        li.Caption  := Items[i].Caption;
        li.SubItems := Items[i].SubItems;
      end;

  lv2.Items.EndUpdate;
end;
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 07.07.03 12:56 
@MathiasSimmack: die Zeile
ausblenden Delphi-Quelltext
1:
li.SubItems := Items[i].SubItems;					

könnte (sofern für die Eigenschaft SubItems keine Set-Methode deklariert wurde) Probleme machen (weiß jetzt nicht ob das der Fall ist)! Aber wenn ich schon mit Objekten arbeite und diese bereits Methoden zum einfachen kopieren der Daten bereitstellen benutze ich diese auch... ;)
ausblenden Delphi-Quelltext
1:
li.SubItems.Assign(Items[i].SubItems);					

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Stoffel1984 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: Mo 07.07.03 13:34 
Hallo ihr Beiden,

vielen herzlichen Dank! Es funktioniert jetzt so wie ich es mir vorgestellt habe. :D

Viele Grüße,

Stoffel