Settings template?

C

Clive Lumb

Hi,

I'm looking for a Windows Forms (VS 2008) template for my application
settings.
Ideally I would like to be able to call the IDE settings page during
run-time (it's an app for admins so it doesn't need any checking etc.).
Is there a way to do this? (I doubt it)
Has anybody come across a template to reproduce the settings tab?

Many TIA
Clive
 
C

Clive Lumb

Cor,

I said "Windows Forms", no asp involved at all.
I have however found a quick and easy way to populate a DataGridView with
the settings, so I can make the form myself quite easily.
If it interests anybody else, here is the code (you need a DatagridView with
three columns, first two set to "read-only"):

For Each MySetting As System.Configuration.SettingsProperty In
My.Settings.Properties

Me.DataGridView1.Rows.Add(New String() {MySetting.Name,
My.Settings(MySetting.Name).GetType.ToString,
My.Settings(MySetting.Name).ToString})

Next

Clive
 
C

Clive Lumb

Clive Lumb said:
Cor,

I said "Windows Forms", no asp involved at all.
I have however found a quick and easy way to populate a DataGridView with
the settings, so I can make the form myself quite easily.
If it interests anybody else, here is the code (you need a DatagridView
with three columns, first two set to "read-only"):

For Each MySetting As System.Configuration.SettingsProperty In
My.Settings.Properties

Me.DataGridView1.Rows.Add(New String() {MySetting.Name,
My.Settings(MySetting.Name).GetType.ToString,
My.Settings(MySetting.Name).ToString})

Next

Clive
In case anybody is interested, here's the code to save any changes that you
make to the settings in the Gridview above. I took me a while to suss out
the type conversion.
'Run though the DataGridView and commit changes

'Column 0 contains setting name

'Column 1 contains setting data type

'Column 2 contains setting value

Dim myRow As DataGridViewRow

For Each myRow In Me.DataGridView1.Rows

With myRow

Try

Dim TypeName As String = .Cells(1).Value

Dim myType As System.Type = System.Type.GetType(TypeName)

My.Settings(.Cells(0).Value) = Convert.ChangeType(.Cells(2).Value, myType)

Catch ex As Exception

MsgBox("Error saving settings : " + ex.Message)

End Try

End With

Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top