J
JezB
I'm binding a checkbox to a Y/N value from the database, and providing
format/parse events to handle the conversion between Y/N and true/false
states :-
Binding b = new Binding("Checked", myView, "YNField");
b.Format += new ConvertEventHandler(boolFormat);
b.Parse += new ConvertEventHandler(boolParse);
myCheckBox.DataBindings.Add(b);
private void boolFormat(object sender, ConvertEventArgs e)
{ if (e.Value.ToString() == "Y" || e.Value.ToString() == "")
e.Value = true;
else e.Value = false;
}
private void boolParse(object sender, ConvertEventArgs e)
{ if ((bool)e.Value == true) e.Value = "Y";
else e.Value = "N";
}
This seems to work fine, but I have noticed that the Parse event is not
fired immediately on changing the checkbox. It fires when (for example), I
move to a different tab page or close the form. I have tried putting the
following into the CheckedChanged event of the checkbox to force it :-
BindingManagerBase bm = BindingContext[myView, "YNField"];
bm.EndCurrentEdit();
but it still doesn't work. Any ideas ?
format/parse events to handle the conversion between Y/N and true/false
states :-
Binding b = new Binding("Checked", myView, "YNField");
b.Format += new ConvertEventHandler(boolFormat);
b.Parse += new ConvertEventHandler(boolParse);
myCheckBox.DataBindings.Add(b);
private void boolFormat(object sender, ConvertEventArgs e)
{ if (e.Value.ToString() == "Y" || e.Value.ToString() == "")
e.Value = true;
else e.Value = false;
}
private void boolParse(object sender, ConvertEventArgs e)
{ if ((bool)e.Value == true) e.Value = "Y";
else e.Value = "N";
}
This seems to work fine, but I have noticed that the Parse event is not
fired immediately on changing the checkbox. It fires when (for example), I
move to a different tab page or close the form. I have tried putting the
following into the CheckedChanged event of the checkbox to force it :-
BindingManagerBase bm = BindingContext[myView, "YNField"];
bm.EndCurrentEdit();
but it still doesn't work. Any ideas ?