How do I create dynamic data binding?

  • Thread starter Thread starter Tobias Johansson
  • Start date Start date
T

Tobias Johansson

Hi,

I am developing a C# component for technical analysis of stock data.
Currently, the component provides its own functionality for data
binding which makes it very easy to modify settings at runtime for
different objects in the component. The following code shows how this
is done.

// fill a ObjectSettings object with the variables which should be
modified at runtime
override public void GetSettings(ObjectSettings settings)
{
settings.AddInt("movingAverage", 50, "Moving Average", "The number
of days the moving average is based on");

}
// load the changed variables
override public void LoadSettings(ObjectSettings settings)
{
movingAverage = settings.GetInt("movingAverage");
}

My question is, could I do the same thing by using the data binding
functionality provided by .NET? How is this done then? My component is
not based on Windows Controls but i guess that will make no
difference.

Cheers
Tobias Johansson
 
Hi
what you can do it that you add app.config file to your project , then
under the appsettings tag you would add an "add" tag to each ObjectSetting
that you want to configure at runtime .....
<configuration>
<appSettings>
<!-- User application and configured property settings go here.-->
<add key="MyObject.Text" value="run time value" />
</appSettings>
</configuration>
then from inside your code ..........
define Configuration.AppSettingsReader
System.Configuration.AppSettingsReader configurationAppSettings = new
System.Configuration.AppSettingsReader();
then use it to access your settings
this.Text =
((string)(configurationAppSettings.GetValue("MyObject.Text",
typeof(string))));


.... however , there is one thing that you should notice thought , the
application configuration file is read only once when the progam starts
calling it , so any changes done after that " while the program is runnting
, will not take effect ... hope that would help

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Back
Top