简体   繁体   English

在VB.NET中使用INI文件填充组合框

[英]Populate Combo box with INI file in VB.NET

I'm a new leaner with Vb.NET and trying to populate a combo box with a particular section from the INI file. 我是Vb.NET的新学习者,并尝试使用INI文件中的特定部分填充组合框。

For example, my INI file contains: 例如,我的INI文件包含:

[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. 我想在表单加载时用月份部分下的值填充其中一个,用指定的单个INI文件中日期部分的值填充其他。

I'm using VS Express 2013 for Windows and using VB.NET as the language. 我正在使用Windows的VS Express 2013,并使用VB.NET作为语言。

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. 编辑:我已经检查了有关读取/写入INI /文本文件的相关文章,但是其中大多数都指向使用不同的INI / TEXT文件,读取所有行或以所需的格式/结构设置INI / TEXT,这不是问题。我可以提出要求。

-Deepak -Deepak

There is no direct way for manipulating with INI files in .NET. 没有直接的方法来处理.NET中的INI文件。

Also INI files consist of key/value pairs, for example like this: INI文件也由键/值对组成,例如:

[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: 如果可以使用适当的INI结构,那么我建议您使用我的库来完成INI文件的处理:

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

Here is how you would achieve your task for the above provided INI content: 这是您如何完成上面提供的INI内容的任务:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM