Binding User Settings to Controls

G

Guest

I made a User control that contains several check boxes and text boxes. I
then added properties to the user control to contain the values in these
controls. Finally, I bound these properties to user scope settings created
with the Settings Designer. At program start-up, everything looks fine. Each
control within the user control has the correct values. The problem occurs
when saving any changes I make to the values in the controls. If I were to,
for example, change the values in three controls, and did a
(Settings).Default.Save(), only the first setting would get properly updated.
The rest of the properties revert to their default values and the values in
the individual controls get changed back to what they were at start-up.

Any Ideas?

Thanks in advance.

Bob Costello.
 
A

AlexS

To modify and save modified settings you need to update datasource for
settings with new values.

So you need to use binding with
DataSourceUpdateMode.OnPropertyChanged

If you use DataBindings of course for your control. If not, you have to
ensure settings.Default.PropSetting is modified when corresponding property
is modified - manually if necessary.

Looks like this is your issue. Without looking at your binding and saving
code.

HTH
Alex
 
G

Guest

I don't think it is my problem. I bind the properties thru the designer and
the code is like you describe. I could of course not use binding and manually
change the properties myself. However, that would defeat the purpose of using
the control.

I have a simple test project that illustrates the problem very clearly. Is
there anyway I can post a zip file containing the project?

Thanks for the response.

Bob
 
A

AlexS

I believe designer by default doesn't set
DataSourceUpdateMode.OnPropertyChanged - last time when I checked my C#
Express.
Might be worng though. When I bound setting to form property in designer it
was not saved until I bound it manually. That's what I remember.

As about code - can you post it as text in the message body? For user
control you might have also inheritance issues if you override or new base
class properties.

Alex
 
G

Guest

Here is description of my simple project. I have a user control with 4 check
boxes. With the Designer, I can bind the Checked property of each control to
different Application settings. This works fine. However, what I need to do
is insert this control into 2 or more forms and have the check states in each
instance bound to different settings. So I added four bool Properties to my
user control, say CheckState1, CheckState2, CheckState3 and CheckState4

Then I insert my user control into 2 forms and bind as follows:

Form1 :

CheckState1 - Setting 1
CheckState2 - Setting 2
CheckState3 - Setting 3
CheckState4 - Setting 4

Form2:

CheckState1 - Setting 5
CheckState2 - Setting 6
CheckState3 - Setting 7
CheckState4 - Setting 8

In both forms, only CheckState1 works properly.

I can email a zip file of my simple project if you like.

Regards,

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top