xorpas 4 Posted June 25, 2021 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
corneliusdavid 214 Posted June 25, 2021 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. 1 Share this post Link to post
xorpas 4 Posted June 25, 2021 (edited) 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 June 25, 2021 by xorpas Share this post Link to post
corneliusdavid 214 Posted June 25, 2021 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. 1 Share this post Link to post
xorpas 4 Posted June 25, 2021 I can't Understand what line you mean Please Can you modify this code to work Share this post Link to post
corneliusdavid 214 Posted June 25, 2021 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. 2 Share this post Link to post
xorpas 4 Posted June 25, 2021 Thank you It Work a Perfetc Now thank you again Share this post Link to post