ComponentOne DataObjects for .NET
Data Binding
DataObjects for .NET (Enterprise Edition) > Schema Objects > Data Binding

Using a C1DataSet component as your data source, you can bind data-aware components such as a grid or a text box to the data. The C1DataSet component exposes table view rowsets. Data-aware controls can bind to any of these rowsets. To bind to a table view rowset, set the DataSource property of the data-aware control to the C1DataSet component and open the DataMember property combo box. It will show the selection of available table views. Select the table view you wish to bind to.

DataObjects for .NET also supports master-detail (parent-child) data binding. Parent and child table views are related by View Relations. You can bind one control to a master (parent) table view and another control to a detail (child) table view. After doing this, the detail control will show the child rows related to the parent row that is current in the master control at the moment. Parent-child hierarchy is shown in the DataMember property combo box as a tree of view relations starting from topmost (master) table views. Topmost table views, roots of parent-child hierarchies, are distinguished by the leading underscore in their names. The same table view also appears in the DataMember list without an underscore, as a stand-alone table view. Select a stand-alone table view if you do not want this data-aware control to participate in a parent-child hierarchy. Select a topmost master table view, starting from underscore, if you want to bind it to a master (topmost parent) rowset. Select a node in a hierarchy tree, a view relation name, if you want to bind it to a child in a parent-child hierarchy.

You can also bind data-aware controls at run time, setting their DataSource and DataMember properties, for example:

To write code in Visual Basic

VB
Copy Code
ParentGrid1.DataMember = "_Customers"
ParentGrid1.DataSource = dataSet1
ChildGrid1.DataMember = "_Customers.Customers-Orders"
ChildGrid1.DataSource = DataSet1

To write code in C#

C#
Copy Code
parentGrid1.DataMember = "_Customers";
parentGrid1.DataSource = dataSet1;
childGrid1.DataMember = "_Customers.Customers-Orders";
childGrid1.DataSource = dataSet1;

Here Customers is the parent table view, Orders is the child table view, Customers-Orders is a view relation between them.

Another run-time option is to bind directly to the table view's C1DataTable object, as in the following example:

To write code in Visual Basic

VB
Copy Code
Dim Dt As C1DataTable
Dt = C1DataSet1.TableViews("Customers")
DataGrid1.DataSource = Dt

To write code in C#

C#
Copy Code
C1DataTable dt = c1DataSet1.TableViews["Customers"]
dataGrid1.DataSource = dt

If you need additional sorting and filtering, you can bind to a C1DataView component, both at design time and at run time:

To write code in Visual Basic

VB
Copy Code
DataGrid1.DataSource = DataView1

To write code in C#

C#
Copy Code
dataGrid1.DataSource = dataView1;

C1DataView allows filtering and sorting the data using its RowFilter and Sort properties. The RowFilter property filters data rows according to a Boolean expression. If you need a more advanced filtering algorithm that cannot be specified as a simple expression you can use the GetRows event to filter data in code.

C1DataView can also be used to filter/sort the data set itself, using the IsDefault property. If IsDefault = False (default), filtering/sorting is applied to the C1DataView component only, affects only controls bound to that C1DataView. If IsDefault = True, filtering/sorting defined in the C1DataView is applied to the data set itself, affects all controls bound to the data set in any way, not just those using the C1DataView as their DataSource. This filtering/sorting applies to hierarchical master-detail binding as well as to simple binding.

Another design-time option for data binding is to bind to a C1DataTableSource that is attached to a certain table view of a data set. Using a C1DataTableSource allows you to handle business logic events in your client application code, in addition to the business logic specified in the data library (see Business Logic for details). Using C1DataTableSource is mandatory if your client application works in virtual mode (see Tutorial 4: Virtual Mode: Dealing with Large Datasets for details).

If you bind third-party (not ComponentOne or Microsoft) controls to DataObjects for .NET data sources, some of them (very few) may work incorrectly with notifications, that is, with the IBindingList.ListChanged event. DataObjects for .NET uses a slightly different notification scheme than ADO.NET does. DataObjects for .NET notifications are fully .NET data binding-compliant and optimized for data bound controls. All ComponentOne bound controls and Microsoft bound controls work properly with this notification scheme. In fact, all data bound controls should work with DataObjects for .NET notifications without problems, but in the non-ideal world that can be broken. To prevent this problem and allow using any bound controls, DataObjects for .NET provides a special NotificationModeFlags property.