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

7.3 Using Hierarchical Grids

The hierarchical grid interface includes virtual functions that allow you to specify child grid types and custom initialization steps.

To specify a custom grid type for the child grid, you must first create a derived parent grid type so that the virtual methods responsible for creating a child can be overridden.


The steps for creating a .NET control-derived class while retaining designer functionality are not straightforward. "Deriving from GridControl with Designer Functionality" describes the pitfalls. You can find this article in Readme.rtf, which is located in the Docs subdirectory of your Objective Grid for Microsoft .NET installation directory.

  1. Following the steps described in "Deriving from GridControl with Designer Functionality," create a new hierarchical grid class with the following declaration:

      using Stingray.Grid;
      …
      public class HierGrid : Stingray.Grid.GridControl
      {
      ...
      
  2. Replace the GridControl type that is instantiated in your form class so that this new hierarchical grid type is used instead.

  3. Add the following override in the HierGrid class:

      public override GridControl InstantiateChildAt(int nRow)
      {
        return new ChildGrid();
      }
      

    This override modifies the default child grid type that is created when the user expands a row.

  4. Define the ChildGrid type by adding the following class declaration after the HierGrid class but in the same file:

      public class ChildGrid : Stingray.Grid.GridControl
      {
      ...
      

    At this point, the parent and child grid classes are declared and the form is modified to instantiate these types instead.

  5. To add scroll bars to the child grids, add the following override to the HierGrid parent class:

      public override void InitializeChildAt(int nRow,
             GridControl child)
      {
        child.SetScrollBarMode(ScrollBarId.Both,
          ScrollBarVisibility.Automatic, false);
        base.InitializeChildAt( nRow, child );
      }
      
  6. To initialize the parent and child grids with text, add a handler for the GridInitialized event and add the following code:

      private void grid1_GridInitialized(object sender,
       System.EventArgs e)
      {
        grid1[2,2].Style.Value = "Cell (2,2)";
        gridControl[3,3].Style.Value = "Cell (3,3)";
        Stingray.Grid.GridControl child = 
          grid1.GetChildAt(2, true);
        child[2,1].Style.Value = "Child cell (2,1)";
      }
      


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.