Cannot data bind to a control when Control.Visible == false
What you could do is make the control visible, and make it invisible again once the binding has changed.
this.checkBox_WorkDone.Visible = true;
this.checkBox_WorkDone.BindingContextChanged += (object sender, EventArgs e) => {
this.checkBox_WorkDone.Visible = false;
};
Not very pretty, but it works.
I ran in to this exact situation before. Until the control is viable for the first time some back-end initialization never happens, part of that initialization is enabling the data binding. You must call CreateControl(true)
before data binding works. However, that method it is a protected method so you must do it though reflection or by extending the control.
Via reflection:
private static void CreateControl( Control control )
{
var method = control.GetType().GetMethod( "CreateControl", BindingFlags.Instance | BindingFlags.NonPublic );
var parameters = method.GetParameters();
Debug.Assert( parameters.Length == 1, "Looking only for the method with a single parameter" );
Debug.Assert( parameters[0].ParameterType == typeof ( bool ), "Single parameter is not of type boolean" );
method.Invoke( control, new object[] { true } );
}
All events will be deferred until the control has Created
set to true.