S
Seth Gecko
Hi
I have a custom usercontrol (a sort of grid) in which I want to store
the width of all columns. I only want to do this during runtime, when
the user has adjusted them to whatever width he/she prefers.
Elsewhere in my application I use a custom class, which inherits
ApplicationSettingsBase and this works fine. For this usercontrol, I
would do same, so I have created the small class, listed below. Since
my usercontrol will reside on a number of forms, I have to have
different settings for each instance of the usercontrol. According to
MSDN, the SettingsKey is exactly what I need. Except, I can't get it
to work. Neither the constructor shown, nor setting
[UserSettingsInstance].SettingsKey = "SomeText" has any effect. The
SpreadWidth returned is the same no matter the value of SettingsKey.
MSDN mentions that usercontrols have to implement
IPersistComponentSettings, but that is a little vague and I only want
to store settings during runtime, not designtime.
Suggestions, please?
Private Class UserSettings
Inherits System.Configuration.ApplicationSettingsBase
Public Sub New(ByVal settingsKey As String)
MyBase.New(settingsKey)
End Sub
<Configuration.UserScopedSetting()> _
Public Property SpreadWidth() As List(Of Single)
Get
If (Me.Item("SpreadWidth") Is Nothing) Then
'This only happens the very first time we run this
application
Me.Item("SpreadWidth") = New List(Of Single)
End If
Return CType(Me.Item("SpreadWidth"), List(Of Single))
End Get
Set(ByVal value As List(Of Single))
Me.Item("SpreadWidth") = value
End Set
End Property
End Class
I have a custom usercontrol (a sort of grid) in which I want to store
the width of all columns. I only want to do this during runtime, when
the user has adjusted them to whatever width he/she prefers.
Elsewhere in my application I use a custom class, which inherits
ApplicationSettingsBase and this works fine. For this usercontrol, I
would do same, so I have created the small class, listed below. Since
my usercontrol will reside on a number of forms, I have to have
different settings for each instance of the usercontrol. According to
MSDN, the SettingsKey is exactly what I need. Except, I can't get it
to work. Neither the constructor shown, nor setting
[UserSettingsInstance].SettingsKey = "SomeText" has any effect. The
SpreadWidth returned is the same no matter the value of SettingsKey.
MSDN mentions that usercontrols have to implement
IPersistComponentSettings, but that is a little vague and I only want
to store settings during runtime, not designtime.
Suggestions, please?
Private Class UserSettings
Inherits System.Configuration.ApplicationSettingsBase
Public Sub New(ByVal settingsKey As String)
MyBase.New(settingsKey)
End Sub
<Configuration.UserScopedSetting()> _
Public Property SpreadWidth() As List(Of Single)
Get
If (Me.Item("SpreadWidth") Is Nothing) Then
'This only happens the very first time we run this
application
Me.Item("SpreadWidth") = New List(Of Single)
End If
Return CType(Me.Item("SpreadWidth"), List(Of Single))
End Get
Set(ByVal value As List(Of Single))
Me.Item("SpreadWidth") = value
End Set
End Property
End Class