0

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

Edited by pritaeas: Moved to VB.NET

2
Contributors
2
Replies
15
Views
2 Years
Discussion Span
Last Post by djjeavons
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.