Solved

Save and load Listview content

Posted on 2010-11-21
4
612 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
[X]
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
  • 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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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 and create keystrokes in Netbeans IDE 8.0 for Windows.

632 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