-1

I want to save settings for each Item in a ListView control. For example:

I selected Item 1 and setting:

Checkbox1 = checked
Checkbox2 = checked
Checkbox3 = unchecked
ComboBox1 = Combo1
Textbox1 = 123
Textbox2 = " "

=> Save setting.

Selected Item 2 and setting:

Checkbox1 = unchecked
Checkbox2 = checked
Checkbox3 = unchecked
ComboBox1 = Combo5
Textbox1 = abc
Textbox2 = nothing

=> Save setting.

And when I selected Item 1 or Item 2 again, it will restore the setting which I set before. [Image for Example][1]

Recommended : using ListView.SelectedIndexChanged.

Note: The ListView item count is not read-only, it can be increased.

johnnyRose
  • 7,310
  • 17
  • 40
  • 61

1 Answers1

0

You can create two classes, an Item Class containing the properties for each of the controls in your ListView Item, and a Collection class, derived from generic like a List<Item> or ObservableCollection<Item> then you can implement inside the collection class a WriteXml and a ReadXml to save and load the content of the controls in a file Using the classes in System.Xml.Serialization or you can if you like it most save the data in JSON using the classes of the framework or those in JSon.Net which is the most popular open source JSON library. You can find plenty of samples to achieve this.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Sabrina_cs
  • 421
  • 3
  • 18
  • thank you very much! But I dont understand much your meaning? Can you give me more example or the link about it? – Past Memory Mar 12 '16 at 17:31
  • http://blogs.dotnetwork.it/sabrina/en/blog/lavorare-con-xml-parte-1/ http://blogs.dotnetwork.it/sabrina/en/blog/lavorare-con-xml-parte-2/ These are a couple of articles I wrote long ago on xml serialization that can help you but really search for xml serialization and you will find many more. P.s. they are in english. – Sabrina_cs Mar 12 '16 at 17:39