I have a feeling this should be easy but I can’t seem to figure it out. I have a settings file, Settings1.settings, that has entries for 20 textboxes (n1 thru n10 and c1 thru c10).
Currently, I save the textbox text to the settings file on Form1_FormClosing like so:
Settings1.Default.n1 = n1.Text;
Settings1.Default.n2 = n2.Text;
...
Settings1.Default.n10 = n10.Text;
Settings1.Default.c1 = c1.Text;
Settings1.Default.c2 = c2.Text;
...
Settings1.Default.c10 = c10.Text;
How would I do something similar with a loop? My thought would be this, but obviously it doesn’t work:
int count = 1
while (count < 11)
{
Control n = panel2.Controls.Find("n" + count.ToString(), true).Single();
Settings1.Default.n = n.Text; //Settings1.Default.n is an invalid statement ...
Control c = panel2.Controls.Find("c" + count.ToString(), true).Single();
Settings1.Default.c = c.Text; //Settings1.Default.c is an invalid statement ...
count++;
}
What’s the proper way to address “Settings1.Default.n + count” ?
Thank you!!
I would suggest changing the type of your settings “n” and “c” to “System.Collections.Specialized.StringCollection” and dealing with it like a regular list or array object, something like:
Alternatively, I think you can also access the settings entries by string like this: