In WinForms with C# 4.0 / C# 2.0, I cannot bind to a control if the control\'s visible field is false:
this.checkBox_WorkDone.DataBindings.Add(\"Visible\", W
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.