I have a form with several controls. There a situtions where ‘textBoxOtherRelationship’ is disable and the text is set to string.empty. But when I then got to another control and tab out the data appears again,while the control remains disabled.
textBoxOtherRelationship.DataBindings.Add(new Binding("Text", _binder, "RelationshipNotes"));
private void ComboBoxRelationShipSelectedValueChanged(object sender, EventArgs e)
{
if ((Constants.Relationship)comboBoxRelationShip.SelectedItem.DataValue == Constants.Relationship.Other)
{
textBoxOtherRelationship.Enabled = true;
if (_formMode != ActionMode.ReadOnly)
{
textBoxFirstName.BackColor = Color.White;
}
}
else
{
textBoxOtherRelationship.Enabled = false;
_model.RelationshipNotes = null;
textBoxOtherRelationship.Text = string.Empty;
if (_formMode != ActionMode.ReadOnly)
{
textBoxFirstName.BackColor = Color.LightYellow;
}
}
}
Hmm.. so I see this line here:
which tells me that you’ve got binding set up between the
Textproperty on the textBoxOtherRelationship and a property called “RelationshipNotes” on the datasource_binder.Great.
So, I’m assuming that the two-way binding works just fine and that when you type something into the
textBoxOtherRelationshipand that control loses focus the underlying RelationshipNotes property is getting updated as well, right?Now, looking at your code there, I don’t think the underlying datasource is being updated when you set the
Textproperty tostring.Emptybecause that usually doesn’t happen until the textbox loses focus and you’ve disabled the control.If you add:
after you set the value to
string.Emptythat string.Empty value will get stored back to the datasource because the databinding will know there is something to update. Programmatically, it doesn’t.I see you have this line:
Is
_model.RelationshipNoteswhat is ultimately supposed to be bound to that textbox?