Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I am using Application settings in My Project.I need your help.How to create a Application settings for Dynamic Property in C#.net.I have 4 Textbox and 3 Buttons in my Testing Project.
Button1 -- For Creating a Dynamic Textbox
Button2 -- To save Dynamic textbox value into Application Setting
Button3 -- To retrieve value from Application settings to Dynamic textbox


Thanks
Regards,
Lakshmi Narayanan.S
Posted
Updated 20-Jun-11 20:48pm
v2

Hope this[^] might help you.

Based on this develop your application setting.
 
Share this answer
 
To dynamically write to app.config, pls look into Read/Write App.Config File with .NET 2.0[^]

Cheers,
Balaji
 
Share this answer
 
Comments
naraayanan 21-Jun-11 3:20am    
Hi Balaji
Thanks for your link.But How can i retrieve from Application settings?
i-balaji-mani 21-Jun-11 3:35am    
Hi, See if this helps. http://stackoverflow.com/questions/2400097/reading-from-app-config-file
I am assuming this is a Windows Application. To get and set Application Settings in this type of application you use

C#
Properties.Settings.Default.yourSettingName
. Thus for your example you would need to do something like this:

C#
private void btnAddTextBox_Click(object sender, EventArgs e)
        {
            //add dynamic textbox
            TextBox tb = new TextBox();
            tb.Top = btnAddTextBox.Top;
            tb.Left = btnAddTextBox.Left + btnAddTextBox.Width + 5;
            tb.Visible = true;
            tb.Name = "dynamicText";
            this.Controls.Add(tb);
        }
        private void btnSaveToSettings_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in this.Controls)
            {
                if (ctrl is TextBox)
                {
                    if (ctrl.Name == "dynamicText")
                    {
                        //save to settings
                        Properties.Settings.Default.dynamicText = ctrl.Text;
                    }
                }
            }
        }
        private void btnRetrieveFromSettings_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in this.Controls)
            {
                if (ctrl is TextBox)
                {
                    if (ctrl.Name == "dynamicText")
                    {
                        //set text to setting
                        ctrl.Text = Properties.Settings.Default.dynamicText;
                    }
                }
            }
        }


This assumes you have a setting in your app.config file called dynamicText

Hope this helps
 
Share this answer
 
v2
Comments
naraayanan 21-Jun-11 4:54am    
HI friend,
as per your coding It's work fine.Please tell how to create Dynamic name in Application setting for using Dynamic Property.In your code
"dynamicText" -- is a Default.But I want "dynamicText" is a Dynamic.
Eg:
I have 3 textbox
DynamicText0,DynamicText1,DynamicText2[Properties.Settings.Default.yourSettingName] will create Dynamically in the Application Setting and I retrieve data from that Application settings.
Regards,
Lakshmi Narayanan.S
Wayne Gaylard 21-Jun-11 5:08am    
the setting called dynamicText has to be created at design time. There would be no point in creating application settings at run time, as there would be no way for you to be able to retrieve the setting because you would have no means of knowing what it is called. If you wanted a setting that could be created at run time, I suggest maybe creating a dictionary<object,object> in your settings, and then you could set and get from the dictionary.
naraayanan 21-Jun-11 7:02am    
Thanks
Try this:
foreach (string key in ConfigurationManager.AppSettings)
{
//Get your key
string value = ConfigurationManager.AppSettings[key];
this.Url = value;
}

For more details, check this link: Reading Keys from App.Config
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900