Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
How to: Bind Objects to Windows Form Controls
Programmer's Guide > OpenAccess ORM Classic (Old API) > OpenAccess Tasks > Bind Data to Controls > How to: Bind Objects to Windows Form Controls

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

Telerik OpenAccess ORM enables you to directly bind controls to objects that have been returned by object queries. This topic will show you how to bind objects to Windows Forms controls.

Using the ObjectView and ObjectProvider Components

In order to bind objects to Windows Forms controls by using the ObjectView and ObjectProvider controls you need to perform the following steps:

  1. Open your control in the visual studio designer.
  2. Open the Toolbox and expand the OpenAccess tab.

     
  3. Drag an ObjectProvider item. The ObjectProvider dialog appears.



    Here, you have several options. The Context Provider drop-down specifies the ObjectScope that will be used. The Persistent Class drop-down specifies which class from the ObjectScope will be used.
  4. Click Finish to close the dialog.
  5. Drag an ObjectView item from the Toolbox. The ObjectView Wizard appears.



    The ObjectProvider drop-down specifies which object provider will be used. The Root type drop-down specifies the class from the object provider that will be displayed.
  6. Click Finish to close the dialog.
  7. The next step is to bind the ObjectView component to a list control. For example, drag a new RadGridView control. Open the Properties pane for the RadGridView control and specify which ObjectView will be used in the DataSource property. When you load your form the control will visualize the class that has been chosen in the ObjectView Wizard.

Using Binding Navigator with ObjectView

There is one very important specific regarding the case when you want to use the BindingNavigator component with ObjectView. The ObjectView exposes a property named StarRowSupport. When it is set to true, it generates new objects with the IEditableObject wrapper. This allows you to use star rows in a grid set. However this property could cause issues for some 3rd part controls or UI elements like the BindingNavigator, which do not support the IEditableObject protocol. To get those UI elements working, you need to set the StarRowSupport property to false.

The ObjectView.StarRowSupport property (when set to true) generates new objects with the IEditableObject wrapper. This is useful in case you want to use star rows in a grid set. However this property could cause issues for some UI elements like the BindingNavigatior. To get those UI elements working, you need to set the StarRowSupport property to false. However this may lead to other problems - with grids having star rows.
Issues with the controls' focus are common cases regarding the BindingNavigator and the StarRowSupport property.

Binding Data by Using the Code Behind

Binding data to win form controls using the code behind can be easily achieved by using Telerik OpenAccess ORM. You will need to go to the event which will trigger the binding. Than you will need to retrieve the object that you wish to bind and using the DataSource property of the control bind it. Here is an example of retrieving all objects from given table and binding them to a grid view.

C# Copy Code
IObjectScope scope = OpenAccessData.ObjectScopeProvider1.GetNewObjectScope();
           scope.Transaction.Begin();
           var result = (from c in scope.Extent<OpenAccessData.Car>() select c).ToList();
           radGridView1.DataSource = result;
           scope.Transaction.Commit();
           scope.Dispose();
VB.NET Copy Code
Dim scope As IObjectScope = OpenAccessData.ObjectScopeProvider1.GetNewObjectScope()
   scope.Transaction.Begin()
   Dim result = (From c In scope.Extent(Of OpenAccessData.Car)() _
                 Select c).ToList()
   radGridView1.DataSource = result
   scope.Transaction.Commit()
   scope.Dispose()