Solved

Save and load Listview content

Posted on 2010-11-21
4
599 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
Getting multiple values from a dataset ASP.NET(VB) 3 37
Name space syntax error 12 43
Export import database 4 43
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

895 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

18 Experts available now in Live!

Get 1:1 Help Now