Binding problems
I recently came across a problem in a GUI i had designed.
The UI was data bound to an object, now when the user
entered some text in a textbox, the change only got
propogated back to the object when the user moved the
focus away from the textbox. Not acceptable!! plus if the
user happened to press the toolbar save button or use
keyboard shortcuts, the value in the textbox was not saved
back to the object.
The problem is that by default, data is written to the
source only when the validating event of the control
fires.
The solution i used was to derive a custom textbox
The solution i used was to derive a custom textbox
public class FastValidatingTextBox : TextBox
{
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged (e);
Binding binding = this.DataBindings["Text"];
if(binding == null)
return;
{
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged (e);
Binding binding = this.DataBindings["Text"];
if(binding == null)
return;
binding.BindingManagerBase.EndCurrentEdit();
}
}
}
}
Using this class as soon the text changes the value gets
committed back to the object.