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.2 Basic Grid Tasks

This section shows you how to change the number of rows and columns in the grid, store data in the grid, and read data from the grid.


The CellValue_CS tutorial, which is located in the Tutorials subdirectory of your Objective Grid for Microsoft .NET installation directory, shows how to write to the grid and read from the grid.

To get started, follow these steps:

  1. In Visual Studio, create a new C# "Windows Application" project:

  2. Drop a GridControl onto the empty form. Enlarge the grid control.

  3. Build and run the application. The grid is empty and has a default size of 30 rows by 30 columns.

  4. Right mouse button click on the form and select View Code. Near the top of the file and right after the last "using…" statement add the following line:

      using Stingray.Grid;
      

3.2.1 Task 1: Changing the Number of Rows and Columns in the Grid

You can change the number of rows and columns in two ways:

To modify the appropriate grid properties from the form designer:

  1. Right-click the form and select Properties. Then, right-click the grid and select Properties. A separate set of properties appears for each.

  2. Modify the grid properties: Find ColCount and RowCount, and modify their values to 8 and 10, respectively. Press Enter. The grid in the designer shows the new sizes.

  3. Build and run the application.

    Figure 5: Grid with Dimensions Set in Property Grid

3.2.2 Task 2: Changing the Number of Rows and Columns after Initialization

  1. In code view, find the constructor (the default name is Form1()).

  2. After the call to the InitializeComponent() method, add the following code:

  3. Build and run the application.

    Figure 6: Grid with Dimensions Set in Code

3.2.3 Task 3: Storing Data in the Grid

  1. Click the form's title bar, and then select the Events button in the properties table (the lightning bolt). A property called Load appears under the Behavior section.

  2. Type FormLoad in the value field and press Enter. A class method called FormLoad() is created. Add the following code:

  3. Build and run the application.

    Figure 7: Data Stored in a Range of Cells

  4. Add the following code right after the code fragment you added above:

  5. Build and run the application.

    Figure 8: Data Stored in Individual Cells

When modifying multiple cells, it is a good idea to call LockUpdate() to prevent unnecessary redrawing and flickering. To call LockUpdate(), write FormLoad this way:

3.2.4 Task 4: Reading Data from the Grid

You can read values from individual cells from the grid using GetValueRowCol():

You cannot use gridControl1[1,1] in place of gridControl1.GetValueRowCol(1,1). gridcontrol[1,1] represents a Cell object, not a Value.

Figure 9: Retrieving Values From a Grid



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.