0

I am looking to create a settings form where the user can see all of the My.Settings

My code goes as follows:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim settignName As String
Dim settingValue As String

For Each setting In My.Settings.PropertyValues
    settignName = setting.Name.ToString
    settingValue = setting.

    dtSettings.Rows.Add(settignName, settingValue)
    Console.WriteLine(settignName, settingValue)

   Next

End Sub

enter image description here

enter image description here

JayV
  • 3,238
  • 2
  • 9
  • 14
Jean Camargo
  • 340
  • 3
  • 17
  • 1
    Take a look at this [answer](https://stackoverflow.com/a/45393126/9365244) - I think it will direct you appropriately – JayV Apr 28 '21 at 20:45
  • With `Option Strict On`, you'd have an immediate summary of what's wrong with that code and immediate suggestions that allow to fix it. For example, change your loop in `For Each setting As SettingsPropertyValue In My.Settings.PropertyValues [...] Next`. No late binding, no use of Object, all Properties available in Intellisense, no mistakes. – Jimi Apr 28 '21 at 20:56

2 Answers2

0
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim settignName As String
    Dim settingValue As String

    For Each setting As System.Configuration.SettingsPropertyValue In My.Settings.PropertyValues
        settignName = setting.Name.ToString
        settingValue = setting.PropertyValue.ToString

        dtSettings.Rows.Add(settignName, settingValue)
        Console.WriteLine(settignName, settingValue)
    Next

enter image description here

Jean Camargo
  • 340
  • 3
  • 17
0

This works for me. My.Settings.Properties is a collection of SettingProperty. You can then access the properties of SettingProperty like Name, PropertyType and DefaultValue.

This code requires Imports System.Configuration

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    For Each s As SettingsProperty In My.Settings.Properties
        Debug.Print($"{s.Name} - {s.PropertyType} - {s.DefaultValue}")
    Next
End Sub
Mary
  • 14,926
  • 3
  • 18
  • 27
  • [How to get the current value of a Property Setting at run-time](https://stackoverflow.com/a/60117461/7444103) – Jimi Apr 29 '21 at 05:51