Saving listview to text file.

Posted on 1998-08-28
Last Modified: 2008-03-04
What is the best way to save the contents of a listview to a text file? Any examples would help a lot.

Question by:Kmiller
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1338058
Hi Kmiller,

In fact I made a component, descendant from TListView that has a SaveToFile method.

If you can wait till Monday I can send you the source code (It's in my office...)


Accepted Solution

mirek071497 earned 100 total points
ID: 1338059
The easiest way is to use something like this:

procedure TForm1.SaveBtnClick(Sender: TObject);
var st : TFileStream;
  st := TFileStream.Create( 'c:\test.res', fmCreate );
  st.WriteComponent( ListView1 );;

procedure TForm1.LoadBtnClick(Sender: TObject);
var st : TFileStream;
  st := TFileStream.Create( 'c:\test.res', fmOpenRead );
  st.ReadComponent( ListView1 );;

however this proc reads the settings for the ListView1.too. If you don't like this you can create invisible mListView and assign items from visible to invisible.

You can of course travell over the items with for i:=0 to ListView1.Items.Count and save nodes and subnodes.


Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
creating threads in delphi 1 202
Twebbrowser add css to the header 3 53
Firemonkey Queue list 1 51
Get monday of current week where a week always starts on monday 2 37
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question