I need help when i try to save the value of my buttons it says that it cannot convert 1 dimensional array to system.collections.arraylist which is the option i am using for my saving. I have seventeen buttons in total that i would like to save the text from. Any help would be appreciated. It's in visual basic.

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        My.Settings.ButtonValues = **{Button4.Text, Button5.Text}**   << PROBLEM          
    End Sub
End Class

Edited 1 Year Ago by pritaeas: Moved to VB.NET


You would probably need to use the AddRange method to add to the ArrayList.

However, why use an ArrayList when you could use a StringCollection for this. For example, change your ButtonValues type to System.Collections.Specialized.StringCollection in your properties and then add the following to your Form Load event:

        If My.Settings.MyButtonValues IsNot Nothing Then
            Button1.Text = My.Settings.MyButtonValues(0)
            Button2.Text = My.Settings.MyButtonValues(1)
            My.Settings.MyButtonValues = New Specialized.StringCollection
        End If

The above ensures that if no data is available then the collection will be initialised, otherwise, the values from each element of the collection will be assigned to your buttons text properties.

When saving, you will need to clear the collection before adding the text values back in order not to keep appending to the collection:

        My.Settings.MyButtonValues.AddRange({Button1.Text, Button2.Text, Button3.Text})


This article has been dead for over six months. Start a new discussion instead.