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

3.3 Cell Types

This section shows you how to modify the attribute of a cell by embedding a control, disable cells, make a cell readonly, cover cells, and merge cells.


The CellAttribute_CS tutorial, which is located in the Tutorials subdirectory of your Objective Grid for Microsoft .NET installation directory, shows how to use styles, covered cells, floating cells, and merged cells.

To get started, follow these steps:

  1. Use the steps in Section 3.2.2 to set the initial grid size to 5 rows and 5 columns.

  2. Turn off the grid lines: Go to the design view for Form1.cs. Select the grid, and then find the Design section in the properties grid. Set DrawGrid to false.


    DrawGrid is a property of the form; it is not a Rogue Wave property.

  3. Replace the code in FormLoad() with the following code:

  4. Build and run the application.

    Figure 10: A Small Grid

3.3.1 Task 1: Modify the Attribute of a Cell by Embedding a Control

  1. In FormLoad(), replace this line of code:

      // ... more stuff to be added here
      

    with the following code:

      // Change the cell style in cell (1,1) so that it 
      // contains a drop down box with 3 choices.
      Style s2 = gridControl1[1,1].Style;
      s2.Control = Stingray.Grid.ControlType.DropDown;
      s2.ChoiceList = "Choice 1\nChoice 2\nChoice 3";
      
  2. Build and run the application.

  3. Select cell A:1. It turns into a drop-down list from which you can choose Choice 1, Choice 2, or Choice 3, as shown in Figure 11.

    Figure 11: Cell With An Embedded Control

  4. Select any cell and change its value.

    Figure 12: Modified Cell

3.3.2 Task 2: Disabling Cells

  1. Before the line gridControl1.LockUpdate(prevLock); in FormLoad(), add the following code:

      Style s3 = gridControl1[2,2].Style;
      s3.Enabled = false;
      
  2. Build and run the application.

  3. Compare the behavior of cell B2 with the other cells by trying to select it using the mouse or cursor keys. You cannot make cell B2 active.

  4. Click cell B2 while pressing the CTRL key, and then press the delete key. The contents of that cell are deleted.

3.3.3 Task 3: Making a Cell Readonly

Making a cell readonly is similar to disabling it. Below this code:

add the following code:

3.3.4 Task 4: Covering Cells

Make one cell cover a number of adjacent cells by adding the following code:

Figure 13: Covered Cells

3.3.5 Task 5: Merging Cells

This task requires modifying one of the grid-wide properties.

  1. Using the form designer, activate the properties for gridControl1.

  2. Under the Behavior section, locate the MergeCells property and set its value to DelayEval.

  3. Add the following code fragment to the LoadForm() method:

      // Merged Cells
      Style sMerged = new Style();
      sMerged.MergeCell =
         MergeCellType.BothDirectionsAndSameStyle;
      sMerged.Value = "2002";
      gridControl1[3,2].Style = sMerged;
      gridControl1[4,2].Style = sMerged;
      gridControl1[5,2].Style = sMerged;
            
      sMerged.Value = "2003";
      gridControl1[3,3].Style = sMerged;
      gridControl1[4,3].Style = sMerged;
      gridControl1[5,3].Style = sMerged;
      gridControl1[3,4].Style = sMerged;
      gridControl1[4,4].Style = sMerged;
      gridControl1[5,4].Style = sMerged;
      
      sMerged.Dispose();
      
  4. Build and run the application.

Figure 14: Merged Cells



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.