This is because by default, whencontrols data bound to a source, theDataSourceUpdateMode is set to OnValidation, which means, the source will be update when the control property is validated, when you click on the save button, the focus leaves from the editing control, and if the input is validated, the changes will be automatically affect to the application settings.
To avoid this, we can set up the binding by code manually without using designer, set the DataSourceUpdateMode to Never, and save the changes to the application settings when clicks on the save button by calling the WriteValue() method of the Binding object.
See my sample for the details
Code Snippet
partial class Form14 : Form
{
public Form14()
{
InitializeComponent();
}
private void Form14_Load(object sender, EventArgs e)
{
this.textBox1.DataBindings.Add("Text",
Properties.Settings.Default, "test",true, DataSourceUpdateMode.Never);
}
private void button1_Click(object sender, EventArgs e)
{
//force the TextBox to write the changes back to the source
this.textBox1.DataBindings[0].WriteValue();
MessageBox.Show(Properties.Settings.Default.test);
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show(Properties.Settings.Default.test);
}
}
Best Regards Zhi-xin Ye
|