1

I'm a new leaner with Vb.NET and trying to populate a combo box with a particular section from the INI file.

For example, my INI file contains:

[Month] 
Jan 
Feb 
Mar

[Date] 
1 
2 
3

I've a form with two combo boxes. I want to populate one of them with the values under Month section and other with Date section values from the specified single INI file when form loads.

I'm using VS Express 2013 for Windows and using VB.NET as the language.

Thanks in advance for any pointers.

Edit: I've checked related posts on reading/writing INI/Text files but most of them either point to using different INI/TEXT files, read all lines or set up the INI/TEXT in a desired format/structure which is not something I can do sue to requirements.

-Deepak

  • possible duplicate of [Reading/writing an INI file](http://stackoverflow.com/questions/217902/reading-writing-an-ini-file) – shf301 May 04 '15 at 11:04
  • I've checked related posts on reading/writing INI/Text files but most of them either point to using different INI/TEXT files, read all lines or set up the INI/TEXT in a desired format/structure which is not something I can do sue to requirements. – Deepak Gupta May 05 '15 at 07:11

1 Answers1

0

There is no direct way for manipulating with INI files in .NET.

Also INI files consist of key/value pairs, for example like this:

[Month] 
Jan = 1
Feb = 2
Mar = 3

In case you can use the appropriate INI structure then I can suggest you to use my library to accomplish INI files processing:

https://github.com/MarioZ/MadMilkman.Ini

Here is how you would achieve your task for the above provided INI content:

Dim ini As New IniFile
ini.Load("path to your INI file")

For Each key In ini.Sections("Month").Keys
    ' Jan, Feb and Mar
    Me.ComboBox1.Items.Add(key.Name)
    ' 1, 2 and 3
    Me.ComboBox2.Items.Add(key.Value)
Next
Mario Z
  • 4,328
  • 2
  • 24
  • 38
  • Thanks Mario for your inputs. Right now I'm not supposed to change the INI structure and need to keep it as it is. But I'll see if I can change the structure after talking to my designer and then definitely would use your library. Thanks once again. – Deepak Gupta May 05 '15 at 07:09