Skip to content

I have a problem for ini File

yusuf Kurt

Asked Jul 28, 2012, 6:20 AM EDT2 answers
Share
LinkedInX
i can write listbox in ini file, but  i can't write ini file in listbox :S

this code write only one index


string dosyadan = ini.Read("Liste","0");


                listBox1.Items.Add(dosyadan.ToString());

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    kardesim tam olarak ne yapmak istiyorsun beraber yardimim dokunur belki
    0
  • 0
    Hi Kurt, you can use this C# library to both read and write your ini files.
    For example let's say you have something like the following "Sample.ini" content:

    [ListBoxItems]
    ListBoxItem = Value 1.
    ListBoxItem = Value 2.
    ListBoxItem = Value 3.

    You can read it into a ListBox controle like this:
    C#
    private void btnLoad_Click(object sender, EventArgs e)
    {
        IniFile file = new IniFile();
        file.Load("Sample.ini");
        IniSection listBoxSection = file.Sections["ListBoxItems"];
     
        this.listBox1.Items.Clear();
        this.listBox1.BeginUpdate();
     
        foreach (var key in listBoxSection.Keys)
            this.listBox1.Items.Add(key.Value);
     
        listBox1.EndUpdate();
    }
    Also you can write your ini content from the ListBox content like this:
    C#
    private void btnSave_Click(object sender, EventArgs e)
    {
        IniFile file = new IniFile();
        file.Load("Sample.ini");
        IniSection listBoxSection = file.Sections["ListBoxItems"];
     
        listBoxSection.Keys.Clear();
        foreach (var item in this.listBox1.Items)
            listBoxSection.Keys.Add("ListBoxItem", item.ToString());
     
        file.Save("Sample.ini");
    }
    0