I want to store user input of server names once saved from inside an application. I get an error in the settings for index out of bounds in my SettingsForm class (error line indicated below). I believe my ServerName property is only of size one so how would I go about changing this? Or is something else need to be changed in my code?
I am unsure about storing the multiple strings to one property. I have been trying different things but I am new to C# and WinForms applications. Here is the code I have been trying to work out:
UserSettings class:
[UserScopedSetting()]
[DefaultSettingValue("Enter Server Name")]
public String[] ServerName
{
get
{
return (String[])this["ServerName"];
}
set
{
this["ServerName"] = (String[])value;
}
}
SettingsForm class:
private void saveSettingsButton_Click(object sender, EventArgs e)
{
//loop through all servers
for (int i=0; i<serverCounter.Value; i++)
{
TextBox currentTextBox = (TextBox)servers[i, 0];
us.ServerName[i] = currentTextBox.Text; //ERROR
currentTextBox.DataBindings.Add("Text", us, "ServerName");
}
us.Save();
this.Close();
}
public List<string> ServerNames { get; set; }and then just add to that list...