Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Save and load Listview content

Posted on 2010-11-21
4
Medium Priority
?
613 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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: …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

705 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