ComponentOne Data Source for Entity Framework
ComponentOne LiveLinq / Getting Started with LiveLinq / Hierarchical LiveLinq Binding / Traditional WinForms Implementation
In This Topic
    Traditional WinForms Implementation
    In This Topic

    Our sample application will consist of the following elements:

    This is what the final application will look like:



    The basic implementation is simple, since Visual Studio handles most of the data binding related tasks automatically. In fact, the entire application can be written without a single line of code.

    Here are the steps:

    1. Create a new WinForms application
    2. Use the Data | Add New DataSource menu and add a reference to the NORTHWND.MDF database. Accept all the default options offered by the wizard, and pick all the tables in the database.
    3.  Add the controls to the form as shown on the image above: one ComboBox, one DataGridView, four TextBox controls, and a few Label controls.

    At this point, the application has access to the data and it has controls to show and edit the data. To connect the controls to the data, follow these steps:

    1. Add a new BindingSource component to the form
    2. Select the new BindingSource component, select its DataSource property in the property window, and use the drop-down editor to select the NORTHWINDDataSet data set.
    3. Still with the BindingSource component selected, use the drop-down editor set the DataMember property to “Categories”.

    The final step is to select each data bound control and bind it to the BindingSource component:

    For the ComboBox, set the following properties:

    C1DataSource          bindingSource1
    DisplayMember  CategoryName
    ValueMember     CategoryID

    For the DataGridView, use the drop-down editor in the property grid to set the DataSource property to FK_Products_Categories, the item that appears under bindingSource1 and represents the products under the currently selected category. The image below shows what the drop-down editor looks like just before the selection is made:



    Finally, select each of the TextBox controls and use the drop-down editor in the property window to bind the Text property to the corresponding element in the currently selected product. For example:



    Repeat this step to bind the other TextBox controls to the UnitPrice, QuantityPerUnit, and UnitsInStock fields.

    The application is now ready. Run it and notice the following:

    This is the traditional way of doing data binding in WinForms. Visual Studio provides rich design-time support and tools that make it easy to get applications started. Of course, real applications typically require you to add some code to implement specific logic.