1stGrid - Step 4
This section gives the steps required to complete Step 4 of the 1stGrid tutorial. Step 4 enables the Objective Grid for .NET formula engine, and configures the grid documents to sum numbers in column two, from row 2 through row 11.
If you don't want to keep Step 3, then skip to “Enable the Formula Engine” to continue adding the Step 4 features to Step 3.
Create a New Project
1. Right click Solution ‘1stGrid’ in Solution Explorer.
2. From the context menu that appears, select Add | New Project.
Click Visual C# Projects.
Select Windows Forms Application.
Set Name to “Step 4”.
Click OK.
3. Right click and delete AssemblyInfo.cs and Form1.cs.
4. From the command prompt or from the Windows Explorer:
Delete all of the remaining Step 4 project and source files.
Copy all of the Step 3 source and project files into the Step 4 directory.
Rename Step 3.* to Step 4.*.
5. Visual Studio will indicate that the project has changed. Select Discard to discard any cached Step 4 project files.
6. Right click Step 4.
7. From the context menu that appears, select Set As Startup Project.
Enable the Formula Engine
The following steps enable the formula engine.
1. Open Form1.cs in design mode.
2. Select the form. Change the following form properties for Form1:
Set Text to “1stGrid Tutorial Step 4".
3. Open the Design View for the GridDocument class.
4. Select the grid control in the GridDocument form.
5. Select the properties for the GridControl.
6. Expand the Features property (in the GridControl category).
Set EnableFormulaEngine to true.
Set EnableWorkSheetFunctions to true.
Add Event Handlers
The following steps add event-handling code for the GridInitialized and EndEditing events. You handle the GridInitialize event by adding some simple titles and a formula to the grid. The formula sums the numbers in column 2, rows 2 through 11. You handle the EndEditing event by validating any user input, which should be empty text or numeric data.
1. Select the events for the GridControl in the property grid (click on the lightning bolt in the property grid).
2. Double click the GridInitialized method, and add the following implementation for the GridInitialized method:
gridControl1[1,2].Style.Value = "Values";
gridControl1[12,1].Style.Value = "Sum:";
gridControl1[12,2].Formula = "=SUM(B2:B11)";
3. Select the events for the GridControl in the property grid (click the lightning bolt).
4. Double click the EndEditing event, and add the following validation code:
Cell cell = gridControl1.CurrentCell;
if (cell.Col == 2 && cell.Row >= 2 && cell.Row <= 11)
{
bool isDigits = true;
for (int i = 0; isDigits && i < cell.Style.Value.Length; ++i)
{
isDigits = Char.IsDigit(cell.Style.Value, i);
}
 
if (!isDigits)
{
MessageBox.Show("Invalid Numeric Value");
e.IsValid = false;
}
}
5. Add the following using declaration at the top of the file GridDocument.cs:
using Stingray.Grid;
6. Build and run the completed application.
Congratulations! You've completed the final step of the 1stGrid tutorial.