Programmatically Data Binding User Interface Controls

When you set a control's BindingSource programmatically at run time, if you do not also set the BindingSourceMember (which isn't required for DataGrids), you must call the form-level RegisterBoundControl method to bind the user interface control to the business object.

For example, in C#:

grdOrders.BindingSource = "Orders";
this.RegisterBoundControl(grdOrders);

And in VB .NET:

grdOrders.BindingSource = "Orders"
Me.RegisterBoundControl(grdOrders)

The reason for this, is the act of setting the BindingSourceMember property is what normally triggers the registration of the user interface control with the business object. Based on this, you could also ensure the control is registered properly by setting the control's BindingSourceMember after setting the BindingSource.

For example, in C#:

grdOrders.BindingSource = "Orders";
grdOrders.BindingSourceMember = null;

And in VB .NET:

grdOrders.BindingSource = "Orders"
grdOrders.BindingSourceMember = Nothing

In this example, setting the BindingSourceMember to null, or an empty string binds the user interface control to the default table of the Orders business object.


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 07/05/04
Comment or report problem with topic