hi all again

i want to save my 3 columns of listview with data in vb.net built in settings saver

how i can do that and how i can load it back when form load.

i write something like this

My.Settings.advance_settings.Add(TextBox2.Text)
My.Settings.advance_settings1.Add(TextBox1.Text)
My.Settings.advance_settings2.Add(Date.Today)

my.settings.save()

it will save the data but how i will load it

please reply

Edited 1 Year Ago by Dani: Formatting fixed

Is there any Add() method to save data in settings?
You can use the following.
to save application settings values.

My.Settings.MyAppUserName = TextBox1.Text
My.Settings.Save()

To retrieve

TextBox1.Text = My.Settings.MyAppUserName

Edited 1 Year Ago by Shark_1

Shark with this method I can retrive and save data from textbox. But I need method for listview save and retrieve data for listview

ListViews display lists of data. So first you need a data class.
Second, a collection List<Data> as the ItemsSource for your ListView.
Third, in Settings.settings a Name, of type string, with Scope of User.
Now you can serialize/deserialize List<Data> to settings.

        [Serializable]
        public class TestMe
        {
            public TestMe()
            {
            }
            public TestMe(string name, int number)
            {
                Name = name;
                Number = number;
            }
            public string Name { get; set; }
            public int Number { get; set; }
        }
                List<TestMe> testMeObjects = null;
                XmlSerializer xmlSerializer = null;
                StringWriter writer = null;
                StringReader reader = null;
                StringBuilder sb = null;
                try
                {
                    testMeObjects = new List<TestMe>();
                    testMeObjects.Add(new TestMe("Apple", 0));
                    testMeObjects.Add(new TestMe("Banana", 1));
                    testMeObjects.Add(new TestMe("Orange", 2));
                    sb = new StringBuilder();
                    writer = new StringWriter(sb);
                    xmlSerializer = new XmlSerializer(typeof(List<TestMe>));
                    xmlSerializer.Serialize(writer, testMeObjects);
                    Settings.Default.TestMeObjects = sb.ToString();
                    reader = new StringReader(Settings.Default.TestMeObjects);
                    testMeObjects = (List<TestMe>)xmlSerializer.Deserialize(reader);
                }
                catch(Exception ex)
                {
                }

hi SteveDotNet
i tried your solution but it giving me error it not working the way i want .

The data of settings are stored in App.config file. It is an xml file. You can show the settings data in a listview.

Dim litm As New ListViewItem
For i A integer = 0 To My.Settings.Properties.Count - 1
    litm = ListView1.Items.Add(My.Settings.Properties("MyUserName" & i + 1).Name, 0)
    litm.SubItems.Add(My.Settings.Properties("MyUserName" & i + 1).DefaultValue)
Next

use of an .xml file to store application settings would give you more flexibility.

Shark_1 thanks for your reply. this is for saving but how i can able to retrive it on form_load event

Edited 1 Year Ago by OMER AHMED

i make one example with shark code check attachment ... now how it will work i mean where it will store my listview information and how i can able to retrive it

Attachments Capture.JPG 57.74 KB

The Properties, which are created at design time , always store in App.ocnfig file. It is an XML file. So, Settings.Save() never does any effect on this file.
When you have open the Settings Tab in Properties Window, the names and values you have seen there, always retrived by vb IDE from app.config file.
You can open and see it in your IDE.
To retrive the setting values programatically, the codes should be like

 ListView1.Items.Clear()
        For i As Integer = 0 To My.Settings.Properties.Count - 1
            lstItem = ListView1.Items.Add(My.Settings.Properties("MyUser" & i + 1).Name)
            lstItem.SubItems.Add(My.Settings.Properties("MyUser" & i + 1).DefaultValue)
        Next

To save the Values to settings programitically is

 lstItem.SubItems(1).Text = TextBox1.Text

        My.Settings.Properties(lstItem.Text).DefaultValue = TextBox1.Text
        My.Settings.Save()

But the scope of these new values depands on the lifetime of the program, i.e. you can use these value when the program runs, but when it shuts down the values would be vanished. When you again run it, you get the default values which are assigned at design time.

It could be overcome, by manipulating the App.config file.
http://stackoverflow.com/questions/3925308/is-there-a-config-type-file-for-visual-studio-add-in
http://stackoverflow.com/questions/25040243/how-to-save-changes-to-app-config-file-from-runtime-for-a-visual-studio-add-in
http://stackoverflow.com/questions/19429477/how-can-i-change-my-app-config-files-connection-string-at-runtime
http://www.codeproject.com/Articles/18128/Modifying-app-config-File
http://www.neolisk.com/techblog/vbnet-read-write-appconfig

Edited 1 Year Ago by Shark_1

This question has already been answered. Start a new discussion instead.