Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Grid User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

4.4 Using Objective Grid in a WinForm

One straightforward way to integrate MFC-based projects with .NET libraries is to set the /clr compiler option and use C++/CLI. Stingray Objective Grid samples are provided with a /clr build configuration to demonstrate compatibility with this approach.

This section discusses two possible ways for integrating Objective Grid into a WinForm:

Simple samples that demonstrate these approaches are shipped with Stingray Studio:

More advanced samples are available in the Rogue Wave Knowledge Base kb.roguewave.com/kb/). Specifically, see Using Objective Grid with C++/CLI at kb.roguewave.com/kb/index.php?View=entry&EntryID=1400.

The procedures below reference Section 4.1.1, "Using the Objective Grid Static Libraries," in this chapter for more detailed information on how to perform particular steps.

4.4.1 Direct Use of Objective Grid in a WinForm

To embed a grid in a WinForm:

  1. Use the Visual Studio App Wizard to create a Visual C++\CLR\Windows Form Application project GridForm.

  2. Add grid resources, as described in Step 2 of Section 4.1.1.

  3. Add #include to the stdafx.h file, as described in Step 4 of Section 4.1.1.

  4. Add GXInit() to the InitInstance() method, as described in Step 5 of Section 4.1.1.

  5. Add the following immediately after class CmyApp (to initialize grid libraries):

  6. Add a member to class Form1:

  7. Initialize the grid, using this code:

  8. Clean up memory in the destructor:

  9. Optionally, add _GXDLL to the Preprocessor definitions, as described in Step 4 of Section 4.1.3.

  10. Build and run the project.

4.4.2 Use of Objective Grid in a .NET Control

To embed a grid in a WinForm:

  1. Use the Visual Studio App Wizard to create a Visual C++\CLR\Windows Form Control Library project Grid.

  2. Add grid resources, as described in Step 2 of Section 4.1.1.

  3. Add #include to the stdafx.h file, as described in Step 4 of Section 4.1.1.

  4. Add the following immediately after namespace Grid {…}:

  5. Add this member to class GridControl:

  6. Iinitialize the grid, using this code:

  7. Expose the APIs to call from the parent program:

  8. Clean up memory, as described in Step 8 of Section 4.4.1.

  9. Build the control.

  10. Add a new project to the solution in any .NET language program; here, we'll use Other Languages |Visual C# |Windows Forms Application.

  11. Open Form1.

  12. Select Tools | Choose Toolbox Items, then click Browse. Navigate to and select Grid.dll built in Step 9.

    For x64 Build Configurations:

    For x64 build configurations (or "AnyCPU" on an x64 machine), any control built with /clr (or even /clr:pure) throws an error when you try to add it to the Toolbox; controls built only with /clr:safe are valid for the Toolbox. This is a current Visual Studio limitation. As a workaround, you can use a control built with x64 and /clr by adding code to WinForms manually, rather then using the Toolbox.

    To do so, set the configuration to Win32, use the Toolbox to add the control built with Win32, and then set the x64 build configuration and build it. The reference should be set to the GridControl project, rather then to a particular assembly.

    Alternatively, save the Windows Forms Designer generated code and use it for initialization of an x64 control in a project with an x64 build configuration, like so:

  13. Add a reference to the Grid project in the Windows Forms Application.

  14. Initialize GridControl with the following code:

    To use an embedded pushbutton, you can add the following to class Form1:

  15. Build and run the solution.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.