I have a Windows Form with a number of Textboxes. I bind them to a DataSource as the Form Loads.
public partial class FormSettings : Form
{
private readonly DbContext _context = new DbContext();
public FormSettings()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
_context.OrderEntrySettings.Load();
SettingsBindingSource.DataSource = _context.OrderEntrySettings.Local.ToBindingList();
Binding saNbinding = new Binding("Text", SettingsBindingSource, "InvoiceNumber");
InvoiceNumberTextBox.DataBindings.Add(saNbinding);
Binding pthNbinding = new Binding("Text", SettingsBindingSource, "SalesOrderExportPath");
PathTextBox.DataBindings.Add(pthNbinding);
<snip>
…
</snip>
}
One of the Textboxes is bound to a Directory Path (string) Property. If I type in a new directory in the Path Textbox and hit my save button, The path saves just fine.
But, If I change the Text Property on the Textbox to the SelectedPath from a FolderBrowserDialog dialog and then hit save, the Textbox Text shows the directory I selected but the Entity is not modified and nothing gets saved back to the database.
As a workaround, I set both the Path Textbox Text and set the Property from the context to the SelectedPath.
Why does a Bound Textbox not modify its associated property if the Text value is set programmatically?