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

10.5 RaceAttendance

This sample illustrates properties of the Stingray.Grid.Style class by formatting and analyzing data from a series of races. It also demonstrates:

Some grid-wide properties can be set only at design time. If you attempt to set them at runtime, an error message is displayed.

At runtime, as you select each cell, the Configurations->CurrentCell group in the properties sheet changes to reflect the properties of the selected cell. You can see and experiment with the properties.

Nearly the entire grid is constructed by code contained within the Form1.FormLoad() method. Look at the source code as you read through this sample. Each major section of the code is identified by // Section #: ..., which matches the following sections.

The application has four major components:

Figure 56: RaceAttendance Form Design

10.5.1 Connecting the Property Grid to the Grid

You can easily embed a grid and property grid in the same form by dragging and dropping both components onto a form, but you need to tie them together so that changes in one are reflected in the other. This is accomplished with a single line:

10.5.2 Adding Data to the Grid

The second section of code formats part of the grid to present the raw data used by the rest of the sample program. It used properties and attributes such as background color, merged cells, and alignment.

  1. A Stingray.Grid.Range object is created and refers to a rectangular region of cells from A1 to E5. Because the range object uses integer indices, A1 translates to the coordinate (1,1) and E5 translates to (5,5). The cells in this range are painted with white as a background color and serve as a table of raw values to be used elsewhere.

  2. The merged cells technique is used to create a center-aligned title for the table. To enable the MergedCells property of the grid:

    The title spans the width of the grid and is positioned in the center by filling all five cells with the same value (Race Event Attendance), and by setting the MergeCell and HorzAlign properties of each cell.

  3. To make the process more efficient, a Style object is created, the appropriate properties set, and then applied to the range A1 through A5 (grid coordinates (1,1) through (1,5)) with the call:

    Each cell in the range A1..A5 has exactly the same value, but only one copy of the title is displayed because the cells are merged.

  4. To keep the title from being inadvertently changed:

  5. Column titles (such as 2001) and rows names (such as Mt. Hood Summit Sprint) are added. The Style applied to each row title has the EllipseType set to EllipseType.DotEllipse. When you run the application for the first time, you may not see any evidence of "…" in the row titles. You can force the ellipses to appear if you make the 'A' or 'B' columns narrower.

  6. Additional Style attributes applied to the row titles are Enabled (set to false) and ToolTip (set to the same value as the text). Setting Enabled to false stops you from selecting the cell(s). Setting ToolTip to the same value as the text causes a pop up tag to display the full cell text, which is useful if some of the cell is obscured.

  7. The table of raw data is filled in. The Style applied to each of these cells includes green text and allows only numeric values.

10.5.3 Formulas

The third section shows how to store formulas in a cell.

If you want to store a simple value such as a string or a numeric, do something like this:

or this:

Storing a formula or an expression is a bit different. You cannot do this:

or this:


This behavior may change in future versions of Objective Grid for Microsoft .NET.

To store formulas, use the SetExpressionRowCol method of the GridControl class:

The expressions stored are of the form =X1+X2+X3. You could just as easily use the form =X1..X3.

10.5.4 Controls and Event Handling

The fourth section calculates the average for a selected year.

  1. Select a year from the drop-down box in cell B13 (which may not be visible unless the cell is active). The average for the selected year is placed in the adjacent cell.

    The code uses control embedding and event handling —responding to events from a control embedded in a cell. In this case, a push button triggers the calculation based upon a value selected in another control.

    The push button control in cell B14 is tied to the private method DispatchLClick(), which is called in response to the event Stingray.Grid.LButtonClickedRowCol. The association of the LButtonClickedRowCol() and the method DispatchLClick() is made by selecting the events list for the GridControl in the property sheet.

  2. Locate the LButtonClickedRowCol event and enter the method name to associate with the event. Once that is done, you can write in the code to test which cell (via row and column) originated the event and respond accordingly.

10.5.5 Miscellaneous

The last section demonstrates features that are not immediately obvious.

10.5.5.1 Creating a Title

Cell A16 illustrates a better way of creating a title that spans several cells. The first technique (Section 10.5.2) put the same string in several cells, and set the MergeCell property in each of those cells. The following technique does not require storing multiple instances of a string.



Previous fileTop of DocumentContentsNo linkNo next 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.