0

I am trying to load all saved my.settings to my textboxes but I am unable to retrieve the saved values. Here is my code

Dim ctrl As Control
    For Each ctrl In Me.Controls
        If (ctrl.GetType() Is GetType(TextBox)) Then
            Dim txt As TextBox = CType(ctrl, TextBox)
            For i As Integer = 1 To 20
                txt.Text = My.Settings("fp" & i)
            Next
        End If
    Next

What is the proper way to do it?Thanks

lorens13
  • 1
  • 1

1 Answers1

0

Generally when you reference a value stored in settings it would be along the lines of ;

My.Settings.<name of the setting>

My.Settings has an Item property which takes the Settings PropertyName (as a string ) as a parameter allowing you to either set or get the relevant value.

So to start with try the following;

Dim ctrl As Control
    For Each ctrl In Me.Controls
        If (ctrl.GetType() Is GetType(TextBox)) Then
            Dim txt As TextBox = CType(ctrl, TextBox)
            For i As Integer = 1 To 20
                txt.Text = My.Settings.Item("fp" & i.ToString)
            Next
        End If
    Next
Dom Sinclair
  • 2,458
  • 1
  • 30
  • 47
  • No luck there, no values were added to the textboxes in the form. I even placed it inside a try-catch phrase but still nothing. But when I try to use a certain text like "test", the word was assigned to all textboxes. The problem is within My.Settings.Item("fp" & i.ToString), I guess – lorens13 Jan 22 '16 at 09:13