Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9041465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:14:45+00:00 2026-06-16T10:14:45+00:00

How can I save the the data in a listview? For example if the

  • 0

How can I save the the data in a listview?

For example if the user has put something into the listview and then closes the application, all that information is then lost. Is there any way of saving the information as soon as they put something into the listView?

This is the code I use to input the information from a textbox to the listView1:

  string[] items = { titletxt.Text, statustxt.Text };
        ListViewItem lvi = new ListViewItem(items);
        listView1.Items.Add(lvi);

UPDATE (29/12/2012)

Thanks for all the help! But I can’t seem to get it working. I have created a really simple form to try and get it working. It has 3 textboxes (NameTxt, AgeTxt, HairColourTxt), a button, and the listview(ListOfPeople).

Here is the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace listview
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string[] items = { NameTxt.Text, AgeTxt.Text, HairColourTxt.Text };
            ListViewItem lvi = new ListViewItem(items);
            ListOfPeople.Items.Add(lvi);
        }
    }
}

I have tried to add the code posted by @user574632 & @Joe & @DmitryKvochkin and I have changed bits but still cant get it to work. I’m not sure what I’m doing wrong? I have tried to add this:

     private void saveListOfPeopleItems(string path, ListView lv)
    {
        var delimeteredListviewData = new List<string>();

        foreach (ListViewItem lvi in lv.Items)
        {
            string delimeteredItems = string.Empty;
            foreach (ListViewItem.ListViewSubItem lvsi in lvi.SubItems)
            {
                delimeteredItems += lvsi.Text + "#";
            }
            delimeteredListviewData.Add(delimeteredItems);
        }

        System.IO.File.WriteAllLines(path, delimeteredListviewData.ToArray());
    }

    private void loadListOfPeopleItems(string path, ListView lv)
    {

        foreach (string line in System.IO.File.ReadAllLines(path))
        {
            lv.Items.Add(new ListViewItem(line.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries)));
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:14:46+00:00Added an answer on June 16, 2026 at 10:14 am

    You need to create the save logic, there’s no automatic method.

    The easiest way is to use Serialization (look for ISerializable) to save to a file of your choice (name it whatever you like): You can save entire objects this way. Here is a simple tutorial on serialization.

    The other method is to parse the listview content into strings (keep only what you need), and you save the strings to a text file (TextReader and TextWriter).

    If you want to save application settings (and not user data), have a look at this link, or this one which might be easier to read.

    Finally, if you need to interact with the data you save regularly, or if you have a lot of data to store, use a database (SQL, mySQL, etc). The latter method is the longest one to implement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to setup a table that can: Save the data on the user's
I'm developing web app that user can save his/her work to server. The data
How can save data into a XML file without user prompt dialog in Action
Is there a way that i can save data on each step in wizard
I try to create a form that can save a person's form data so
I am creating a HTML layout where user can fill the data and save
How can I save data to a file (that I will plot later on)
As part of our app, user can save some data as XML on server
how can I save the ListView and ScrollView items that contain text and images,
How can I save data from an Excel sheet to .RData file in R?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.