From: Hector Santos on
I am trying to use the library to set/get settings. Something that
normally isn't a hard concept when you using your own logic, but I'm
still learning the rich library and wish to use whats there.

But I don't get it. Following all examples, it doesn't seem to take.

To test, I created a Windows form with 3 check boxes and using the
Data Binding to set three corresponding settings:

option1
option2 default checked
option3

How do use this in code so that user changes stick on saving and loading?

Maybe I am seeing this wrong. Its only for the default settings?

I don't wish to hand code the load/saving for each control/option,
isn't that defeating the purpose of the "Data/Property Binding" using
its inherent enumeration interface?

Thanks


--
HLS
From: Jackie on
On 5/29/2010 22:53, Hector Santos wrote:
> I am trying to use the library to set/get settings. Something that
> normally isn't a hard concept when you using your own logic, but I'm
> still learning the rich library and wish to use whats there.
>
> But I don't get it. Following all examples, it doesn't seem to take.
>
> To test, I created a Windows form with 3 check boxes and using the Data
> Binding to set three corresponding settings:
>
> option1
> option2 default checked
> option3
>
> How do use this in code so that user changes stick on saving and loading?
>
> Maybe I am seeing this wrong. Its only for the default settings?
>
> I don't wish to hand code the load/saving for each control/option, isn't
> that defeating the purpose of the "Data/Property Binding" using its
> inherent enumeration interface?
>
> Thanks
>
>

Wouldn't it be better to use ApplicationSettings instead for that purpose?
From: Peter Duniho on
Hector Santos wrote:
> I am trying to use the library to set/get settings. Something that
> normally isn't a hard concept when you using your own logic, but I'm
> still learning the rich library and wish to use whats there.
>
> But I don't get it. Following all examples, it doesn't seem to take.
>
> To test, I created a Windows form with 3 check boxes and using the Data
> Binding to set three corresponding settings:
>
> option1
> option2 default checked
> option3
>
> How do use this in code so that user changes stick on saving and loading?
>
> Maybe I am seeing this wrong. Its only for the default settings?

Without you posting actual code, it's not possible to know for sure what
help you need.

However, if you are talking about the Designer-provided "Settings"
class, which you retrieve from the "Default" property in the class, you
have to call the Save() method after changing any of the values.

If that's not what you're talking about, then you need to be less vague.
Post actual code, a concise-but-complete code example that reliably
demonstrates the problem.

Pete
From: Hector Santos on
Jackie wrote:

> On 5/29/2010 22:53, Hector Santos wrote:
>> I am trying to use the library to set/get settings. Something that
>> normally isn't a hard concept when you using your own logic, but I'm
>> still learning the rich library and wish to use whats there.
>>
>> But I don't get it. Following all examples, it doesn't seem to take.
>>
>> To test, I created a Windows form with 3 check boxes and using the Data
>> Binding to set three corresponding settings:
>>
>> option1
>> option2 default checked
>> option3
>>
>> How do use this in code so that user changes stick on saving and loading?
>>
>> Maybe I am seeing this wrong. Its only for the default settings?
>>
>> I don't wish to hand code the load/saving for each control/option, isn't
>> that defeating the purpose of the "Data/Property Binding" using its
>> inherent enumeration interface?
>>
>> Thanks
>>
>>
>
> Wouldn't it be better to use ApplicationSettings instead for that purpose?


I would think so but it doesn't to take (stick) or I am missing something.

To test/explore the concept, I created a simple C# Windows Form
applications with five checkboxes and in via the Property Editor I
data bound them to

Option1 user setting, default false
Option2 user setting, default true
Option3 user setting, default false
Option4 app setting, default true
Option5 app setting, default false

Checking the project properties setting, matches the result.

I also added a "Save" button on the form.

in Program.cs, I have:

using System.Diagnostics;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Windows.Forms;

namespace TextMFCApplicationSettings
{
public partial class Form1 : Form
{
Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
Properties.Settings settings = new Properties.Settings();

public void log(string fmt, params object[] v)
{
Debug.WriteLine(String.Format(fmt,v));
}

public Form1()
{
InitializeComponent();
log("== AFTER InitializeComponent() ===");
log("Option1={0}", settings.Option1);
log("Option2={0}", settings.Option2);
log("Option3={0}", settings.Option3);
log("Option4={0}", settings.Option4);
log("Option5={0}", settings.Option5);

}
private void btnSaveSettings_Click(object sender, EventArgs e)
{

config.Save(ConfigurationSaveMode.Modified);
//setting.Save(); // tried this too

log("== AFTER Save() ===");
log("Option1={0}", settings.Option1);
log("Option2={0}", settings.Option2);
log("Option3={0}", settings.Option3);
log("Option4={0}", settings.Option4);
log("Option5={0}", settings.Option5);
}
}
}

I just to get the purpose of ApplicationSettings if you have to it
programmatically, which is no sweat, I can write a class to handle it
all very nicely, but if the .NET libraries can handle it, I want to at
least see how it works. All the docs, show how to make properties,
but is very short on the subject of loading and saving and making it
stick.

Note, I even did this, before the save() calls:

//ConfigurationManager.AppSettings["Option1"] =
checkBox1.Checked.ToString();
//ConfigurationManager.AppSettings["Option2"] =
checkBox2.Checked.ToString();
//ConfigurationManager.AppSettings["Option3"] =
checkBox3.Checked.ToString();
//ConfigurationManager.AppSettings["Option4"] =
checkBox4.Checked.ToString();
//ConfigurationManager.AppSettings["Option5"] =
checkBox5.Checked.ToString();

settings.Option1 = checkBox1.Checked;
settings.Option2 = checkBox2.Checked;
settings.Option3 = checkBox3.Checked;
//settings.Option4 = checkBox4.Checked; // not allowed
//settings.Option5 = checkBox5.Checked; // not allowed

to see if it the default can be saved, but that didn't work either.

I am definitely missing something. Whats the "Ah ha" here?

--
HLS
From: Hector Santos on
Peter Duniho wrote:

> Hector Santos wrote:
>> I am trying to use the library to set/get settings. Something that
>> normally isn't a hard concept when you using your own logic, but I'm
>> still learning the rich library and wish to use whats there.
>>
>> But I don't get it. Following all examples, it doesn't seem to take.
>>
>> To test, I created a Windows form with 3 check boxes and using the
>> Data Binding to set three corresponding settings:
>>
>> option1
>> option2 default checked
>> option3
>>
>> How do use this in code so that user changes stick on saving and loading?
>>
>> Maybe I am seeing this wrong. Its only for the default settings?
>
> Without you posting actual code, it's not possible to know for sure what
> help you need.
>
> However, if you are talking about the Designer-provided "Settings"
> class, which you retrieve from the "Default" property in the class, you
> have to call the Save() method after changing any of the values.
>
> If that's not what you're talking about, then you need to be less vague.
> Post actual code, a concise-but-complete code example that reliably
> demonstrates the problem.
>
> Pete


Right, See 2nd post.

I under the designer and default concept. I create UI components with
properties to make this work - to see DEFAULTS.

But I never wait further with real production effort to deal with
saving/reloading of stored properties. I was mostly "learning" the
object layout of the language.

I don't get how run time property change values are saved and reloaded
over the defaults.

The docs seem to suggest that you have to duplicate the coding, but
that doesn't seem right. But all I see are examples where you do have
to .Remove(), .Add() these property settings in code - thats redundant
to me because it means I can create a enumerator to do this, which
is also redundant.

So I am still missing something here.

Thanks

--
HLS