Data-binding to program settings

20 Aug

It is fairly straightforward to use Visual Studio 2005 or 2008 to define application settings at design time. I love this feature because it saved me lots of code lines. It is of cource to manually hook the control events, for instance, a check box is checked, with the status/value of a specific setting variable, or render the value of the setting var with a control. However, this is tedious. It is ideal to data-bind the setting variable to a control, and here is how:

In the figure below, I demonstrate linking the check box’s ‘checked’ status to the boolean setting varible ‘bDirectLogin’.

1. Select the checkbox to data bind

databinding form1.png

2. In the property window, unfold the ApplicationSettings node

databinding form2.png

3. Click the column in the ‘Checked row’, and all the possible variables that can be hooked to the control property will be shown, and select it!

databinding form3.png

4. That is almost done. Remember to save the setting when application exit:

void OnFormClose()




5. Still not perfect! Some times, you will find that the bound setting varible is not working properly, even you modified it, it does not change. There is no way to work around this so far, just redo the above process. Compile and have a cup of coffee now!

Leave a comment

Posted by on August 20, 2008 in Dotnet/C#


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: