Jump to content
xorpas

save all item from listview with DynamicAppearance

Recommended Posts

How can  save all item from listview with DynamicAppearance  I use this code but it save only first item

 

procedure TForm1.ListView1ItemClick(const Sender: TObject;
  const AItem: TListViewItem);
var
  I: integer;
  AItem1: TListViewItem;

  list: TStringList;
begin
  list := TStringList.Create;

  for I := 0 to ListView1.Items.Count - 1 do
  begin
    ListView1.Selected := ListView1.Items[I];

    name := AItem.Data['Text1'].AsString;
    phone := AItem.Data['Text2'].AsString;
    index := AItem.Data['Text3'].AsString;
    list.Add(name + sLineBreak + phone + sLineBreak + index + sLineBreak);

  end;
  list.SaveToFile('C:\Users\Gt\Desktop\TestContactBack.vcf');
  list.Free;
end;

 

Share this post


Link to post

Setting .Selected isn't changing what AItem is pointing to, so AItem never changes. Instead, you would want to assign AItem:

AItem1 := ListView1.Items[I];

Then you could access the item's data.

  • Like 1

Share this post


Link to post

The same problem

procedure TForm1.ListView1ItemClick(const Sender: TObject;
  const AItem: TListViewItem);
begin
  AItem1 := AItem;
  name := AItem1.Data['Text1'].AsString;
  phone := AItem1.Data['Text2'].AsString;
  index := AItem1.Data['Text3'].AsString;

end;
procedure TForm1.MenuItem1Click(Sender: TObject);
var
  I: integer;
  list: TStringList;
begin
  list := TStringList.Create;
  for I := 0 to ListView1.Items.Count - 1 do
  begin
     AItem1 := ListView1.Items[I];
     ListView1.Selected := AItem1;
     list.Add(name + sLineBreak + phone + sLineBreak + index + sLineBreak);
  end;
  list.SaveToFile('C:\Users\Gt\Desktop\TestContactBack.vcf');
  list.Free;
end;

 

Edited by xorpas

Share this post


Link to post

Don't assign the Selected property at all--that's not going to help you. Replace that line with the name, phone, index assignments from ListView1ItemClick.

  • Like 1

Share this post


Link to post

I can't Understand what line you mean Please Can you modify this code to work

Share this post


Link to post
procedure TForm1.MenuItem1Click(Sender: TObject);
var
  I: integer;
  list: TStringList;
  AItem1: TListViewItem;
begin
  list := TStringList.Create;
  for I := 0 to ListView1.Items.Count - 1 do
  begin
     AItem1 := ListView1.Items[I];
     name := AItem1.Data['Text1'].AsString;
     phone := AItem1.Data['Text2'].AsString;
     index := AItem1.Data['Text3'].AsString;
     list.Add(name + sLineBreak + phone + sLineBreak + index + sLineBreak);
  end;
  list.SaveToFile('C:\Users\Gt\Desktop\TestContactBack.vcf');
  list.Free;
end;

You don't need ListView1ItemClick at all for this.

  • Like 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×