0

I am trying to store an array in the settings of my program. I have referenced this other stackoverflow question (https://stackoverflow.com/a/4267845/2916027) on how to make a System.Int32 array in the settings, but now I am having trouble actually using the array itself.

I would like to set the array size (int[100]) and then set/retrieve values from it like any other settings. Whenever i try to access or otherwise manipulate the property in any way, I get the "object reference not set to an instance of an object" error, because the value is null. I'm trying to make it NOT null, but I can't because its already null, can anyone please help??

The array is called InbatecCellPreference

int preferlistcounter = 0;
Int32[] preferlist = new Int32[dgvPrefList.Rows.Count];
for (int i = 0; i < dgvPrefList.Rows.Count; i++)
{
    //initialize the array
    Properties.Settings.Default.InbatecCellPreference.SetValue(0, i);

    if ((bool)dgvPrefList[0, i].Value == true)
    {
        preferlist[preferlistcounter] = Convert.ToInt16(dgvPrefList["CellID", i]);
        //set the array to the value of preferlist
        Properties.Settings.Default.InbatecCellPreference.SetValue(preferlist[preferlistcounter], preferlistcounter);
        preferlistcounter++;
    }
}
//save changes after the loop has completed
Properties.Settings.Default.Save();

** UPDATE, I also realized that the setting Scope in the designer was set to APPLICATION instead of USER. Once i changed it to USER i was able to bypass the READ-ONLY problem**

Community
  • 1
  • 1
metinoheat
  • 118
  • 1
  • 10

0 Answers0