简体   繁体   English

将TextBox值保存到Ini文件

[英]Save TextBox value to Ini File

I have had some great help from another member here already. 我已经从这里的另一个成员那里获得了很大的帮助。 However, I am stuck again. 但是,我再次陷入困境。 I have a cfg file, which is basically the exact same as an Ini file. 我有一个cfg文件,基本上与Ini文件完全相同。 I can load the Sections to ListBox1 just fine and when I select a Section it displays the Key in ListBox2 and when I select a Key it displays the value of that key in TextBox1. 我可以将Sections很好地加载到ListBox1,当我选择一个Section时,它会在ListBox2中显示键,而当我选择Key时,它会在TextBox1中显示该键的值。 That all works perfectly thanks to one of the members here. 多亏了这里的一位成员,所有工作都完美完成。 Now, where I am stuck is, if I want to change the value shown in TextBox1 and save it to the cfg file. 现在,如果我想更改TextBox1中显示的值并将其保存到cfg文件中,就会遇到麻烦。 I have tried the normal method of SaveFileDialog. 我已经尝试了SaveFileDialog的常规方法。 But I don't want to have the option of saving a new file. 但是我不想选择保存新文件。 I just want to change the value in the existing file without showing a Dialog. 我只想在不显示对话框的情况下更改现有文件中的值。 Hope this is making sense. 希望这是有道理的。

Here is the code: 这是代码:

This loads ListBox1: 这将加载ListBox1:

Dim ini As New INI(Environ("USERPROFILE") & "path-to-cfg")
ListBox1.Items.AddRange(ini.GetSectionNames()) 'For all sections

This loads ListBox2 from a selected item in listbox1: 这将从listbox1中的选定项目加载ListBox2:

Dim ini As New INI(Environ("USERPROFILE") & "path-to-cfg")
Dim section As String = ListBox1.SelectedItem
ListBox2.Items.Clear()
For Each item In ini.GetEntryNames(section)
   ListBox2.Items.Add(item)
Next

This displayed a value in TextBox1 from a selected item in ListBox2: 这在TextBox1中显示了ListBox2中选定项的值:

Dim ini As New INI(Environ("USERPROFILE") & "path-to-cfg")
Dim value As String = ListBox2.SelectedItem

TextBox1.Text = ini.GetEntryValue(ListBox1.SelectedItem, ListBox2.SelectedItem)

Any help is so appreciated. 任何帮助都非常感谢。

Cheers, Dan 干杯,丹

Resolved. 解决。

I followed the example on the following link and it worked just fine. 我在以下链接上关注了该示例,并且效果很好。 Thanks anyway for the help. 无论如何,谢谢您的帮助。 Much appreciated. 非常感激。

For those interested: Click Here 对于那些感兴趣的人: 单击此处

Thanks, 谢谢,
Dan

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

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