<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I was thinking of another way to do: just have one big string called
> "AllColWidths" formatted "col1:width1,col2:width2,..." But then for
> every column I'd have to read the whole string and find the width I
> need. I just don't find this solution very satisfying.
>
Well, it *is* an idea. Here's another one.
This is an example of saving and restoring settings that have their own
"section".
This resides in my base form and is inherited by all of my forms. It saves
and then later restores the same setting name, but under the Form Name as
the setting key. I also use a similar structure in a couple of forms to
keep the entries the user has made in the screen so I can repopulate them
when he comes back at another time.
Private _settings As My.MySettings
Private ReadOnly Property Settings() As _
System.Configuration.ApplicationSettingsBase
Get
If _settings Is Nothing Then
_settings = New My.MySettings
End If
Return _settings
End Get
End Property
'In my Form_Closing
SetSettings()
'In my Form_Load
ApplySettings()
Private Sub ApplySettings()
Settings.SettingsKey = Me.Name
Dim theSettings As My.MySettings
theSettings = DirectCast(Settings, My.MySettings)
If theSettings.FormSize <> Drawing.Size.Empty Then
Me.Size = theSettings.FormSize
End If
If theSettings.FormLocation <> Drawing.Point.Empty Then
Me.Location = theSettings.FormLocation
End If
End Sub
Private Sub SetSettings()
Settings.SettingsKey = Me.Name 'THIS is the key, i.e. section name
Dim theSettings As My.MySettings
theSettings = DirectCast(Settings, My.MySettings)
If Me.WindowState = FormWindowState.Normal Then
theSettings.FormSize = Me.Size
Else
'if the form was maximized or minimized, return to the restore
state
theSettings.FormSize = Me.RestoreBounds.Size
End If
theSettings.FormLocation = Me.Location
Settings.Save()
End Sub
Unfortunately, you actually *do* have to have the settings in MySettings in
the Project area. I thought I had figured a way around that, but apparently
not.
I did find this article on MSDN about creating new application settings,
but it's not going to make you happy. It requires you to set up a property
to do it. So unless you can do that programmatically, you seem to be s.o.l.
http://msdn2.microsoft.com/en-us/library/ms171565.aspx
Here's a cheeky idea: You could make a setting called "ColumnWidth", then
set the column name to the key name. This would give you a separate area in
your user.config file for each column, but who cares? It would work. I'd
probably try that out of desperation, and if it didn't work, create a
dictionary (fieldname, column width) and save it in XML by itself.
And just to save you some trouble in case you want to look at the XML
created, this writes to the user.config file, and on my computer (XP), this
goes into
"C:\Documents and Settings\myusername\Local Settings\Application Data\
\myappname\myappname.exe_gobbledybook\versionnumber\user.config"
Good luck. Hope this helps in *some* way!
Robin S.