0

I am currently in the process of creating an application where the user will be able to create announcements. I would like to save the users announcements and have tried everything to save the user input in the form of a setting. Any suggestions/different methods for saving user input would be appreciated.

Current Setting's

My attempt at adding new "Announcements":

private void button1_Click(object sender, EventArgs e)
{
    Properties.Settings.Default.Title[Properties.Settings.Default.MessageNum] = textBox1.Text;
    Properties.Settings.Default.Message[Properties.Settings.Default.MessageNum] = textBox2.Text;
    Properties.Settings.Default.MessageNum++;
    Properties.Settings.Default.Save();
}

Error thrown

{"Object reference not set to an instance of an object."}

settings.settings xml file as requested

<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="WindowsFormsApplication1.Properties" GeneratedClassName="Settings">
  <Profiles />
  <Settings>
    <Setting Name="Title" Type="System.String[]" Scope="User">
      <Value Profile="(Default)" />
    </Setting>
    <Setting Name="Message" Type="System.String[]" Scope="User">
      <Value Profile="(Default)" />
    </Setting>
    <Setting Name="MessageNum" Type="System.Int32" Scope="User">
      <Value Profile="(Default)">0</Value>
    </Setting>
  </Settings>
</SettingsFile>

1 Answers1

0

Use a StringCollection instead of string[]. StringCollection is supported by VS.

enter image description here

  • Upon changing the code I started receiving this error {"Object reference not set to an instance of an object."} – Pink Commando Aug 01 '16 at 03:06
  • You've updated your question, and that `settings.settings xml file` should work now. But that exception sounds like a VS error, so try restarting it. –  Aug 01 '16 at 03:14
  • [Okay, have a look here.](http://stackoverflow.com/questions/20130448/store-string-array-with-values-in-application-settings) –  Aug 01 '16 at 03:22