This is a migrated thread and some comments may be shown as answers.

PageView Control Data Binding

1 Answer 113 Views
PageView
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 25 Apr 2013, 12:29 PM
I am developing a WinForms application using a RadPageView control with eight tabs. On each tab I have a mix of RadTextBox and RadDropDownList controls all bound to a object using a BindingSource control. When I bind an object to this datasource the SelectedValue on certain drop downs don't always bind on pages after the first one. As soon as I click on the page the SelectedValue updates and it displays the correct value. There doesn't seem to be any pattern to which drop downs have this problem and the ones that have the problem seem to periodically change.

Does anyone know why this happens or if there is a way around it? The problem it is causing me is that when I call ValidateChildren on the form the validation is happening without the values being correct, but when I switch to the page with the error the field is correct but still shows the validation error.

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 30 Apr 2013, 11:19 AM
Hi Dan,

Thank you for writing.

The observed behavior is the default behavior for the Controls in Windows Forms. It seems that the control is not yet fully initialized before it is made visible. I found similar thread on StackOverflow. There is a suggestion to call the internal CreateControl method of the control to force its initialization and this worked fine on my end.
Alternatively, you can select the desired page as you did. Here is the method:

private static void ForceCreateControl(Control control)
{
    object method = control.GetType().GetMethod("CreateControl", BindingFlags.Instance | BindingFlags.NonPublic);
    object 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 });
}

I hope that you find this information useful.

All the best,
Peter
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
PageView
Asked by
Dan
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or