[英]VB.NET Trying to read a System.Collections.Specialized.StringCollection in My.Settings returns an InvalidOperationException
在我的vb.net项目中,我使用Visual Studio的内置设置管理器创建了以下设置:
在尝试读取“颜色”或“分隔符”时,我得到了InvalidOperationException,但读取布尔变量却可以。
在我的配置文件中,找不到我的System.Collections.Specialized.StringCollection变量...
据我所知,设置变量的实例是自动创建的,所以这不是问题。
这是我在其中读取设置的构造函数:
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
My.Settings.Reload()
'INIT Separators
If Not ListView_Separators.Items.Count = 0 Then
ListView_Separators.Items.Clear()
End If
If My.Settings.separators.Count = 0 Then
My.Settings.separators.Add(",")
GenerateListViewItem(",")
Else
For Each seperator As String In My.Settings.separators
GenerateListViewItem(seperator)
Next
End If
Button_Add.Enabled = False
Button_Delete.Enabled = False
'INIT Colors
If DataGridView_Colors.Rows.Count > 0 Then
DataGridView_Colors.Rows.Clear() 'Clear DataGridView
End If
For Each color As String In My.Settings.colors 'Add all Colors to DataGridView
'Add to DataGridView
Dim splitedColor As String() = New String(1) {1, 1}
splitedColor = color.Split("_")
Dim contentText As String
Select Case splitedColor(1)
Case 0
contentText = "New component"
Case 1
contentText = "Removed component"
Case 2
contentText = "Changed Data"
End Select
Dim arrDataGridRow As String() = New String(1) {splitedColor(0), contentText}
DataGridView_Colors.Rows.Add(arrDataGridRow)
Dim dgwStyle As New DataGridViewCellStyle
dgwStyle.ForeColor = Drawing.Color.FromName(splitedColor(0))
DataGridView_Colors.Rows(DataGridView_Colors.Rows.Count - 1).Cells(0).Style = dgwStyle
Next
'INIT View
If My.Settings.appVisible = True Then
Checkbox_Visable.Checked = True
Else
Checkbox_Visable.Checked = False
End If
End Sub
My.Settings.separators.Count引发异常。
有人知道如何处理吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.