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          
        My.Settings.Save()
    End Sub
End Class

Hi

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)
        Else
            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.Clear()
        My.Settings.MyButtonValues.AddRange({Button1.Text, Button2.Text, Button3.Text})
        My.Settings.Save()

HTH

Double posted my above post for some reason.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.