在VB.NET中使用INI文件填充组合框 [英] Populate Combo box with INI file in VB.NET

查看:105
本文介绍了在VB.NET中使用INI文件填充组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Vb.NET的新学习者,试图用INI文件中的特定部分填充组合框.

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

例如,我的INI文件包含:

For example, my INI file contains:

[Month] 
Jan 
Feb 
Mar

[Date] 
1 
2 
3

我有一个带有两个组合框的表格.我想在表单加载时用月份"部分下的值填充其中之一,并用指定的单个INI文件中的日期"部分值填充其他值.

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.

我正在使用Windows的VS Express 2013,并使用VB.NET作为语言.

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

预先感谢任何指针.

我已经检查了有关读取/写入INI/文本文件的相关文章,但是其中大多数都指向使用不同的INI/TEXT文件,读取所有行或以所需的格式/结构设置INI/TEXT,我不能根据要求提起诉讼.

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

推荐答案

没有直接方法来处理.NET中的INI文件.

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

另外INI文件也由键/值对组成,例如:

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

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

如果您可以使用适当的INI结构,那么我建议您使用我的库来完成INI文件的处理:

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

以下是您如何完成上面提供的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

这篇关于在VB.NET中使用INI文件填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆