1
Answer

How to add items in listview from ini file?

sarada

sarada

15y
2.8k
1

Hi,

I am adding items in listview using ini file.When i try to add first item.it is storing properlu,When i try to add another,it is overriding the previous one.I want to store all the items.Is it possible in c#

Answers (1)
0
Deborah Stoddard

Deborah Stoddard

NA 14 0 9y
Yes this is possible, for example here is how you can do that with a help of LINQ and this C# library that can read INI file:
var ini = new IniFile();
ini.Load("Sample.ini");

var listItems = from iniSec in ini.Sections
                from iniKey in iniSec.Keys
                select
                    new ListViewItem(
                        string.Format("KEY NAME: {0}, KEY VALUE: {1}",
                            iniKey.Name, iniKey.Value));

this.listView1.Items.AddRange(listItems.ToArray());