473,465 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C# user.config confusion

Hi,

I have a windows form app which would benefit from the new application
settings support in VS2005.

Say that my form has a single textbox on it. When the form closes I would
like to save the text in that textbox as part as the user level application
settings. When the application restarts I would like that text to be
restored to the textbox.

Because I am not using a built-in property on my form does this mean that I
cannot use the designer to add my setting?

Or, do I *have* to create a custom class derived from
ApplicationSettingsBase and manage everything myself?

No matter how I approach this I cannot seem to get my settings to
"automagically" restore their values at app startup.

Any pointers would be greatly appreciated!

BT

Dec 30 '05 #1
7 2425
Just to provide more information:

Using the designer I added the following setting (using the designer)
Name: MySetting
Type: string
Scope: User
Value: Initial value

public Form1()
{
InitializeComponent();
// Load the data from user.config
textBox1.Text = Properties.Settings.Default.MySetting;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save any of my settings
Properties.Settings.Default.Save();
}

My problem is that textBox1.Text MySetting is not being restored correctly -
it always reverts to its "initial" value.

-BT
"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

I have a windows form app which would benefit from the new application
settings support in VS2005.

Say that my form has a single textbox on it. When the form closes I would
like to save the text in that textbox as part as the user level
application settings. When the application restarts I would like that
text to be restored to the textbox.

Because I am not using a built-in property on my form does this mean that
I cannot use the designer to add my setting?

Or, do I *have* to create a custom class derived from
ApplicationSettingsBase and manage everything myself?

No matter how I approach this I cannot seem to get my settings to
"automagically" restore their values at app startup.

Any pointers would be greatly appreciated!

BT

Dec 30 '05 #2
Ok, I figured it out - of course it was user error.

I was not updating the settings when the text of the textbox was actually
changed! :(

private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.MySetting = textBox1.Text;
}
-BT

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Just to provide more information:

Using the designer I added the following setting (using the designer)
Name: MySetting
Type: string
Scope: User
Value: Initial value

public Form1()
{
InitializeComponent();
// Load the data from user.config
textBox1.Text = Properties.Settings.Default.MySetting;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save any of my settings
Properties.Settings.Default.Save();
}

My problem is that textBox1.Text MySetting is not being restored
correctly - it always reverts to its "initial" value.

-BT
"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

I have a windows form app which would benefit from the new application
settings support in VS2005.

Say that my form has a single textbox on it. When the form closes I
would like to save the text in that textbox as part as the user level
application settings. When the application restarts I would like that
text to be restored to the textbox.

Because I am not using a built-in property on my form does this mean that
I cannot use the designer to add my setting?

Or, do I *have* to create a custom class derived from
ApplicationSettingsBase and manage everything myself?

No matter how I approach this I cannot seem to get my settings to
"automagically" restore their values at app startup.

Any pointers would be greatly appreciated!

BT


Dec 30 '05 #3
BT,

Why not use data binding and just bind the value of the textbox to the
MySetting property on the object? This would probably be much easier.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Ok, I figured it out - of course it was user error.

I was not updating the settings when the text of the textbox was actually
changed! :(

private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.MySetting = textBox1.Text;
}
-BT

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Just to provide more information:

Using the designer I added the following setting (using the designer)
Name: MySetting
Type: string
Scope: User
Value: Initial value

public Form1()
{
InitializeComponent();
// Load the data from user.config
textBox1.Text = Properties.Settings.Default.MySetting;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save any of my settings
Properties.Settings.Default.Save();
}

My problem is that textBox1.Text MySetting is not being restored
correctly - it always reverts to its "initial" value.

-BT
"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

I have a windows form app which would benefit from the new application
settings support in VS2005.

Say that my form has a single textbox on it. When the form closes I
would like to save the text in that textbox as part as the user level
application settings. When the application restarts I would like that
text to be restored to the textbox.

Because I am not using a built-in property on my form does this mean
that I cannot use the designer to add my setting?

Or, do I *have* to create a custom class derived from
ApplicationSettingsBase and manage everything myself?

No matter how I approach this I cannot seem to get my settings to
"automagically" restore their values at app startup.

Any pointers would be greatly appreciated!

BT



Dec 30 '05 #4
Thank you for the suggestion Nicholas and in fact I was just trying to
figure out the correct way to do that.

I am not sure how to create the binding between
Properties.Settings.Default.MySetting and the Text property of the textBox1
textbox.

textBox1.DataBindings.Add("Text", Properties.Settings, "Default.MySetting
");

Is this correct?

Thanks!
BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uU**************@TK2MSFTNGP11.phx.gbl...
BT,

Why not use data binding and just bind the value of the textbox to the
MySetting property on the object? This would probably be much easier.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Ok, I figured it out - of course it was user error.

I was not updating the settings when the text of the textbox was actually
changed! :(

private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.MySetting = textBox1.Text;
}
-BT

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Just to provide more information:

Using the designer I added the following setting (using the designer)
Name: MySetting
Type: string
Scope: User
Value: Initial value

public Form1()
{
InitializeComponent();
// Load the data from user.config
textBox1.Text = Properties.Settings.Default.MySetting;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save any of my settings
Properties.Settings.Default.Save();
}

My problem is that textBox1.Text MySetting is not being restored
correctly - it always reverts to its "initial" value.

-BT
"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

I have a windows form app which would benefit from the new application
settings support in VS2005.

Say that my form has a single textbox on it. When the form closes I
would like to save the text in that textbox as part as the user level
application settings. When the application restarts I would like that
text to be restored to the textbox.

Because I am not using a built-in property on my form does this mean
that I cannot use the designer to add my setting?

Or, do I *have* to create a custom class derived from
ApplicationSettingsBase and manage everything myself?

No matter how I approach this I cannot seem to get my settings to
"automagically" restore their values at app startup.

Any pointers would be greatly appreciated!

BT




Dec 30 '05 #5
BT,

Almost. I think you want:

textBox1.DataBindings.Add("Text", Properties.Settings.Default, "MySetting");
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thank you for the suggestion Nicholas and in fact I was just trying to
figure out the correct way to do that.

I am not sure how to create the binding between
Properties.Settings.Default.MySetting and the Text property of the
textBox1 textbox.

textBox1.DataBindings.Add("Text", Properties.Settings, "Default.MySetting
");

Is this correct?

Thanks!
BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:uU**************@TK2MSFTNGP11.phx.gbl...
BT,

Why not use data binding and just bind the value of the textbox to the
MySetting property on the object? This would probably be much easier.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Ok, I figured it out - of course it was user error.

I was not updating the settings when the text of the textbox was
actually changed! :(

private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.MySetting = textBox1.Text;
}
-BT

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Just to provide more information:

Using the designer I added the following setting (using the designer)
Name: MySetting
Type: string
Scope: User
Value: Initial value

public Form1()
{
InitializeComponent();
// Load the data from user.config
textBox1.Text = Properties.Settings.Default.MySetting;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save any of my settings
Properties.Settings.Default.Save();
}

My problem is that textBox1.Text MySetting is not being restored
correctly - it always reverts to its "initial" value.

-BT
"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
> Hi,
>
> I have a windows form app which would benefit from the new application
> settings support in VS2005.
>
> Say that my form has a single textbox on it. When the form closes I
> would like to save the text in that textbox as part as the user level
> application settings. When the application restarts I would like that
> text to be restored to the textbox.
>
> Because I am not using a built-in property on my form does this mean
> that I cannot use the designer to add my setting?
>
> Or, do I *have* to create a custom class derived from
> ApplicationSettingsBase and manage everything myself?
>
> No matter how I approach this I cannot seem to get my settings to
> "automagically" restore their values at app startup.
>
> Any pointers would be greatly appreciated!
>
> BT
>
>
>



Dec 30 '05 #6
Thank you Nicholas - for YEARS you have been helping countless thousands of
developers and you are much appreciated.

BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ub**************@TK2MSFTNGP10.phx.gbl...
BT,

Almost. I think you want:

textBox1.DataBindings.Add("Text", Properties.Settings.Default,
"MySetting");
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thank you for the suggestion Nicholas and in fact I was just trying to
figure out the correct way to do that.

I am not sure how to create the binding between
Properties.Settings.Default.MySetting and the Text property of the
textBox1 textbox.

textBox1.DataBindings.Add("Text", Properties.Settings, "Default.MySetting
");

Is this correct?

Thanks!
BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:uU**************@TK2MSFTNGP11.phx.gbl...
BT,

Why not use data binding and just bind the value of the textbox to
the MySetting property on the object? This would probably be much
easier.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Ok, I figured it out - of course it was user error.

I was not updating the settings when the text of the textbox was
actually changed! :(

private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.MySetting = textBox1.Text;
}
-BT

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
> Just to provide more information:
>
> Using the designer I added the following setting (using the designer)
> Name: MySetting
> Type: string
> Scope: User
> Value: Initial value
>
> public Form1()
> {
> InitializeComponent();
> // Load the data from user.config
> textBox1.Text = Properties.Settings.Default.MySetting;
> }
>
> private void Form1_FormClosing(object sender, FormClosingEventArgs e)
> {
> // Save any of my settings
> Properties.Settings.Default.Save();
> }
>
> My problem is that textBox1.Text MySetting is not being restored
> correctly - it always reverts to its "initial" value.
>
> -BT
>
>
> "Bit Twiddler" <bi***********@hotmail.com> wrote in message
> news:%2***************@tk2msftngp13.phx.gbl...
>> Hi,
>>
>> I have a windows form app which would benefit from the new
>> application settings support in VS2005.
>>
>> Say that my form has a single textbox on it. When the form closes I
>> would like to save the text in that textbox as part as the user level
>> application settings. When the application restarts I would like
>> that text to be restored to the textbox.
>>
>> Because I am not using a built-in property on my form does this mean
>> that I cannot use the designer to add my setting?
>>
>> Or, do I *have* to create a custom class derived from
>> ApplicationSettingsBase and manage everything myself?
>>
>> No matter how I approach this I cannot seem to get my settings to
>> "automagically" restore their values at app startup.
>>
>> Any pointers would be greatly appreciated!
>>
>> BT
>>
>>
>>
>
>



Dec 30 '05 #7
BT,

Thanks for the props. Much appreciated.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Thank you Nicholas - for YEARS you have been helping countless thousands
of developers and you are much appreciated.

BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:ub**************@TK2MSFTNGP10.phx.gbl...
BT,

Almost. I think you want:

textBox1.DataBindings.Add("Text", Properties.Settings.Default,
"MySetting");
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thank you for the suggestion Nicholas and in fact I was just trying to
figure out the correct way to do that.

I am not sure how to create the binding between
Properties.Settings.Default.MySetting and the Text property of the
textBox1 textbox.

textBox1.DataBindings.Add("Text", Properties.Settings,
"Default.MySetting ");

Is this correct?

Thanks!
BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:uU**************@TK2MSFTNGP11.phx.gbl...
BT,

Why not use data binding and just bind the value of the textbox to
the MySetting property on the object? This would probably be much
easier.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
> Ok, I figured it out - of course it was user error.
>
> I was not updating the settings when the text of the textbox was
> actually changed! :(
>
> private void textBox1_TextChanged(object sender, EventArgs e)
> {
> Properties.Settings.Default.MySetting = textBox1.Text;
> }
> -BT
>
> "Bit Twiddler" <bi***********@hotmail.com> wrote in message
> news:O$**************@TK2MSFTNGP11.phx.gbl...
>> Just to provide more information:
>>
>> Using the designer I added the following setting (using the designer)
>> Name: MySetting
>> Type: string
>> Scope: User
>> Value: Initial value
>>
>> public Form1()
>> {
>> InitializeComponent();
>> // Load the data from user.config
>> textBox1.Text = Properties.Settings.Default.MySetting;
>> }
>>
>> private void Form1_FormClosing(object sender, FormClosingEventArgs e)
>> {
>> // Save any of my settings
>> Properties.Settings.Default.Save();
>> }
>>
>> My problem is that textBox1.Text MySetting is not being restored
>> correctly - it always reverts to its "initial" value.
>>
>> -BT
>>
>>
>> "Bit Twiddler" <bi***********@hotmail.com> wrote in message
>> news:%2***************@tk2msftngp13.phx.gbl...
>>> Hi,
>>>
>>> I have a windows form app which would benefit from the new
>>> application settings support in VS2005.
>>>
>>> Say that my form has a single textbox on it. When the form closes I
>>> would like to save the text in that textbox as part as the user
>>> level application settings. When the application restarts I would
>>> like that text to be restored to the textbox.
>>>
>>> Because I am not using a built-in property on my form does this mean
>>> that I cannot use the designer to add my setting?
>>>
>>> Or, do I *have* to create a custom class derived from
>>> ApplicationSettingsBase and manage everything myself?
>>>
>>> No matter how I approach this I cannot seem to get my settings to
>>> "automagically" restore their values at app startup.
>>>
>>> Any pointers would be greatly appreciated!
>>>
>>> BT
>>>
>>>
>>>
>>
>>
>
>



Dec 30 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: KennethBohman | last post by:
Hi everybody, Question: how can I use the executable.config-files during installation? The answer might seem obvious, but there is apparently more to it! My itention was, as part of the...
4
by: grs | last post by:
Can a class library have a app.config file. Reason for asking is that the microsoft application blocks all read from myApp.exe.config. How can you use the application blocks if you do not have an...
0
by: Jim Heavey | last post by:
Hello, I am trying to figure out how to add <listeners> to the web config. The book that I am using shows the following: <system.diagnostics> <trace> <listeners> <add ....... />...
2
by: Mark | last post by:
Our team uses VSS. We each have a user.config file for local settings. One developer's file does NOT kick in - it pulls directly from the web.config file. 1. The user.config file is in the...
5
by: Dean Slindee | last post by:
I store several application settings in the project's "app.config" file. I also have a form that reads these values and displays them in a listview so that the user can adjust them. My question...
12
by: Ben | last post by:
I have a group of settings that I'd like to have inherited by multiple sites. I'm trying this, but it's not working. wwwroot\group\web.config wwwroot\group\site1\web.config...
0
by: dgk | last post by:
I've used the Website Administration Tool to create a few roles and users using the default (SQLExpress?) providers. But when I try to to access them using the ProfileManager: lblCnt.Text =...
1
by: Matt F | last post by:
Two of the projects in my solution that both need to use a common user.config file. This is a data application - the executable that is created with the first project is the primary executable...
3
by: Piotrekk | last post by:
Hi I have a problem connected with user.config file. I am using default settings.settings . To settings.settings I am adding one user scope string and one application scope string. Thus...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.