The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

EntitySpaces and the Infragistics WinForm UltraGrid

Last post 05-24-2007, 12:31 AM by David.Parsons. 0 replies.
Sort Posts: Previous Next
  •  05-24-2007, 12:31 AM 2690

    EntitySpaces and the Infragistics WinForm UltraGrid

    This walk-through has one simple goal... document the steps we took to test using an EntitySpaces 2007 v0 collection as the DataSource for an Infragistics WinForm UltraGrid. It does not even scratch the surface of all the features available in the UltraGrid (or any of the many other controls in Infragistics NetAdvantage for .NET.) We just wanted to confirm basic MS DataGridView capabilities.

    We started by opening the EntitySpacesDemo solution, changing the ConnectionString in app.config to connect to our instance of SQL Server's Northwind, compiling, and running. We went to the UI Techniques -> Edit in a Grid Example, and ran it. This was our baseline of what we wanted to accomplish, and confirmed that the EntitySpaces installation had gone according to plan. You can now close the EntitySpacesDemo solution.

    Start a new C# Windows Application project. There are some things that need to be setup before we start dropping controls on the Form, so Right-Click the empty Form that appears, and Click "View Code".

    Right-Click References in Solution Explorer, and add the EntitySpaces references. We just Browsed to the EntitySpacesDemo\Runtime folder and added the following:

    • Core
    • Interfaces
    • LoaderMT
    • SqlClientProvider

    Double-Click Program.cs and add the code for the Loader:

    Code:
    static void Main()
    {
    	EntitySpaces.Interfaces.esProviderFactory.Factory =
    		new EntitySpaces.LoaderMT.esDataProviderFactory();
    
    	Application.EnableVisualStyles();
    	Application.SetCompatibleTextRenderingDefault(false);
    	Application.Run(new Form1());
    }

    Save and close Program.cs.
    Right-Click the Project in Solution Explorer and Click "Add -> Existing Item".
    Navigate to app.config for the EntitySpacesDemo and Add it to the project.
    Right-Click the Project in Solution Explorer and Click "Add -> New Folder".
    Name it "Generated".
    Right-Click the "Generated" folder and Click "Add -> Existing Item".
    Navigate to the "Generated" folder for the EntitySpacesDemo.
    Select all Northwind classes and Add them to the project.
    From the VS Build Menu, Click "Rebuild Solution".
    From the VS Data Menu, Click "Add New DataSource".
    Click "Object" and "Next".
    Navigate down through the Project's BusinessObjects, Click "EmployeesCollection", and "Next".
    Click "Finish".
    From the VS Build Menu, Click "Rebuild Solution".
    In the Form1 Code View add the following using statements:

    Code:
    using BusinessObjects;
    using Infragistics.Win;
    using Infragistics.Win.UltraWinGrid;

    Switch to Design View.
    Drag a Button on to the Form.
    Set its Text to "Save".
    Double-Click the Button. (Takes you to Code View.)
    Switch back to Design View.
    Drag a BindingSource on to the Form.
    Set its DataSource to "EmployeesCollection".
    Drag an UltraGrid on to the Form.
    If the Wizard appears, just click "Finish".
    Set its DataSource to "bindingSource1".
    Click the large "Start" button on the UltraGrid.
    Click "Manage Presets" in the "Basic Settings" tree.
    Click the "Combined" tab.
    Select "Infragistics Standard Look" from the dropdown.
    Click "Apply this Preset to grids created at design time".
    Click the "Apply Preset" button.
    Click the "Apply" button at the bottom right.
    Click "OK".
    In the UltraGrid Properties, switch to Events.
    Double-Click InitializeLayout.

    That should take you back to Code View. Add all the code for the Form as shown below. Notice, except for applying a Preset to the grid, we have not done anything different than we would for any other WinForm project using EntitySpaces. And, except for a couple of UltraGrid Overrides in the InitializeLayout event, the code below should look very familiar.

    Save all your changes, build, and run.

    You should now be in a position to tweak the UltraGrid to your exact specifications. Those changes are well beyond what we can cover. If our Infragistics users have tips on using various Infragistics features with EntitySpaces, please feel free to post them in the Peer to Peer forums.

    We should point out that our first attempt to use the UltraGrid was an exercise in frustration. We never did get the AddNew row to work. The solution was simple. Spend an hour going through the UltraGrid documentation that was installed to the Infragistics Start Menu, before even opening a VS solution. It is a powerful control, and with that power comes complexity. But, just an hour with the docs should give you enough understanding to get the basics.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    using BusinessObjects;
    using Infragistics.Win;
    using Infragistics.Win.UltraWinGrid;
    
    namespace TestInfragistics
    {
        public partial class Form1 : Form
        {
            EmployeesCollection emps = new EmployeesCollection();
    
            public Form1()
            {
                InitializeComponent();
    
                emps = new EmployeesCollection();
                emps.Query.Select(
                    emps.Query.EmployeeID,
                    emps.Query.LastName,
                    emps.Query.FirstName,
                    emps.Query.HireDate,
                    emps.Query.ReportsTo);
                emps.Query.Load();
    
                bindingSource1.DataSource = emps;
                ultraGrid1.DataSource = bindingSource1;
            }
    
            private void ultraGrid1_InitializeLayout(object sender,
                Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                // Displays the add-row on the bottom
                // of each rows collection.
                this.ultraGrid1.DisplayLayout.Override.AllowAddNew =
                    AllowAddNew.TemplateOnBottom;
    
                // Allow selecting rows for deletion with
                // the "Delete" key.
                this.ultraGrid1.DisplayLayout.Override.RowSelectors =
                    DefaultableBoolean.True;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (this.Validate())
                {
                    bindingSource1.EndEdit();
                    emps.Save();
                }
            }
        }
    }

    David Neal Parsons
    www.entityspaces.net
View as RSS news feed in XML