Solved

Save and load Listview content

Posted on 2010-11-21
4
593 Views
Last Modified: 2013-11-26
HI,

I have the methode for saving the listview content to file.
But I don't have the methode for loading the content of the file to listview.

Who can help me?

Greetings, Peter Kiers
private void button3_Click(object sender, EventArgs e)

        {

            TextWriter tw = new StreamWriter("Data\\Glucose.sav");

            StringBuilder listViewContent = new StringBuilder();

            for (int item = 0; item < this.lstvGlucose.Items.Count; item++)

            {

                for (int subitem = 0;

                   subitem < this.lstvGlucose.Columns.Count;

                   subitem++)

                {

                    listViewContent.Append

                    (this.lstvGlucose.Items[item].SubItems[subitem].Text);

                    if (subitem < this.lstvGlucose.Columns.Count - 1)

                        listViewContent.Append(",");

                }

                tw.WriteLine(listViewContent);

                listViewContent = new StringBuilder();

            }

            tw.Close();

        }

Open in new window

0
Comment
Question by:peterkiers
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:abdkhlaif
ID: 34183232
may I ask why are you asking the same question again?
0
 
LVL 1

Accepted Solution

by:
peterkiers earned 0 total points
ID: 34183467
Found it:

Greetings, Peter Kiers
private void button3_Click(object sender, EventArgs e)

        {

            FileStream fsWrite = File.Open("Glucose.dat", FileMode.Create, FileAccess.ReadWrite);

            BinaryFormatter binfmt = new BinaryFormatter();

            binfmt.Serialize(fsWrite, new ArrayList(lstvGlucose.Items));

            fsWrite.Close();

        }

        /*--------------------------------------------------------------------*/

        private void button2_Click(object sender, EventArgs e)

        {

            FileStream fsRead = File.Open("Glucose.dat", FileMode.Open, FileAccess.ReadWrite);

            binfmt = new BinaryFormatter();

            ArrayList deserialized_array_list = (ArrayList)binfmt.Deserialize(fsRead);

            Array listviewitem_array = (deserialized_array_list).ToArray(typeof(ListViewItem));

            lstvGlucose.Items.AddRange((ListViewItem[])listviewitem_array);

            fsRead.Close();

        }

        /*--------------------------------------------------------------------*/

Open in new window

0
 
LVL 3

Expert Comment

by:abdkhlaif
ID: 34195200
cancel the question to save your points
0
 
LVL 1

Author Closing Comment

by:peterkiers
ID: 34216127
This is the best solution because it works great and fast.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now