vb.net - 为什么 My.Settings 没有保存?
问题描述
我在My.Settings
named中有一个设置Categories
。所以在一个模块里面我有一个公共子运行这个代码:
Public Sub DeclareCategories()
Dim currentCategory As String
' GET CURRENT CATEGORIES
currentCategory = My.Settings.Categories
' ADD THE CATEGORY
My.Settings.Categories = currentCategory & frmNewCategory.txtCategoryName.Text & ","
My.Settings.Save()
End Sub
然后,用户将My.Settings.Categories
在单击该表单中的按钮时更新该值frmNewCategory
。这是按钮的代码:
If txtCategoryName.Text <> "" Then
Try
DeclareCategories()
MsgBox("Successfully added the new category!")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
Else
MsgBox("Please enter a category name before adding.", MsgBoxStyle.Critical)
End If
由于某种原因,我的设置没有保存。Categories
也是一个字符串。我什至尝试删除所有currentCategory
东西并保留:
My.Settings.Categories = frmNewCategory.txtCategoryName.Text
My.Settings.Save()
但它仍然没有保存设置。任何建议将不胜感激,谢谢。
解决方案
提醒 My.Settings 仅保存在保存它们的计算机上。示例:您的类别设置将保存在您计算机上的文件中。
如果您将设置保存在“类别”中并将可执行应用程序放在另一台计算机上,则“类别”设置将为空。
此外,检查字符串currentCategory & frmNewCategory.txtCategoryName.Text
以确保字符串实际上不是空的。
推荐阅读
- javascript - 为什么我不能用字符串更新 MySQL?
- sql - 如何选择多对多关系表?
- javascript - 如何让选择选项与禁用和启用提交按钮一起使用
- vue.js - vue-table-2 的自定义搜索框
- javascript - Nodejs从嵌套函数返回结果
- apache-camel - Apache Camel 在处理时手动 NACK 消息
- javascript - 在回调函数的调用之间清空反应状态
- python - 如何填写 QComboBox?
- javascript - 使用 Electron-Builder 的 RaspberryPi SerialPorts 出现问题
- ajax - 如何重新加载表格的一部分?