The value of a SettingsProperty
is stored in its DefaultValue
property. Try the following:
private void button1_Click(object sender, EventArgs e)
{
foreach (SettingsProperty c in Properties.Settings.Default.Properties)
{
if (c.DefaultValue[0,0] == 0)
{
c.DefaultValue[0, 0] = 1;
}
}
}
You might also want to simplify the code using Linq:
private void button1_Click(object sender, EventArgs e)
{
foreach (SettingsProperty c in Properties.Settings.Default.Properties
.Cast<object>()
.Where(c => ((int[,])((SettingsProperty)c).DefaultValue)[0, 0] == 0))
{
c.DefaultValue[0, 0] = 1;
}
}
Or even better in one line of code:
private void button1_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Properties.Cast<object>()
.Where(c => ((int[,])((SettingsProperty)c).DefaultValue)[0, 0] == 0)
.ToList()
.ForEach(c => ((int[,])((SettingsProperty)c).DefaultValue)[0, 0] = 1);
// .ToList() is added because .ForEach() is not available on IEnumerable<T>
// I added .Cast<object>() to convert from IEnumerable to IEnumerable<object>. Then I use the cast to SettingsProperty so you can use the DefaultValue.
}
Finally, this question might be helpful:
C# How to loop through Properties.Settings.Default.Properties changing the values