ExcelLike
The ExcelLike sample demonstrates Objective Grid for .NET features that mimic features of Microsoft Excel:
Current cell
Headers
Scrolling
Selection frame
This sample also demonstrates:
Find and replace
Formula engine and worksheet functions
Scroll tips
Cell and tool tips
Saving a grid in HTML format
The ExcelLike sample is a multiple document interface type of application with a frame containing zero or more grid child windows.
Running the Sample
Build and run the sample. The main frame window of the application is displayed.
Press Ctrl-N or select File | New to create and display a new grid. You may have any number of grids open at one time, within your system’s memory limits. For this part of the example, you need just one grid.
Formula Support
1. In columns A1 through A5, enter some integer and floating point numbers:
2. Add those numbers using the formula =sum(A1..A5) in cell A8:
3. Press enter, and you should see the formula replaced with the result of the formula. If you reselect the cell, the formula is displayed.
You can get a similar result by explicitly referencing each cell in the summation range: =sum(A1+A2+A3+A4+A5).
Copying and Pasting Data and Formulas
1. Select the cells in the range A1 through A8: Click on A1, and then hold down the left mouse button while dragging the selection rectangle down to cell A8.
2. Select Edit | Copy from the menu bar to copy the selected range of cells to the clipboard.
3. Select cell C1, and then select Edit | Paste.
4. Select cell C8 to reveal the formula. The cell range in the sum changed from A1..A5 to C1..C5.
5. To delete a range of selected cells, highlight the cells, and then select Edit | Delete.
Undo and Redo Changes
1. Change some values in the range A1..A5, such as 555.1 in A1 and 8 in A4.
2. Select Edit | Undo and Edit | Redo a few times.
Changes in value and movement of the active cell selection box are affected by Undo and Redo.
Find, Find and Replace
1. Select the first cell in column A1.
2. Select Edit | Find. Search for the number 7.
3. Select Edit | Replace. Search for the number 7 and replace every occurrence with the number 3. Before replacing, the grid looks like this:
After replacing all occurrences of 7 with 3, the grid looks like this:
The sum of 555.1, 55.63, 12, 8, and 19.001 is 649.731 not 649.331 as shown. The 7 in “649.771” was replaced with 3 after the evaluation of the formula.
NOTE >> If the value in a cell results from a formula and contains text that can be replaced, the formula is evaluated, the text is replaced, and then the resulting value replaces the formula.
Saving a Grid in HTML Format
Saving grid data in HTML format is a means of presentation and does not preserve the data. You cannot restore the HTML format to another grid instance.
1. In cell A11, enter the formula =sum(A1..A5).
2. Save the grid by selecting File | Save As | HTML. You are prompted for a filename.
3. View the file using a web browser. The formula (the one you stored in cell A11) is evaluated before the HTML view of the grid is constructed and stored. The formula remains unaltered in this sample.
For another example of saving in HTML format, see “RaceAttendance.”
Design-time Features
Many Objective Grid for .NET features can be set at design time using the property sheet designer:
You can hand-code these properties, but you may find it easier to let the designer help with the work. All available properties are enumerated, as well as their allowable values.
Setting Grid Properties
1. Select the GridDocument.cs designer window, and then select gridControl1 in the drop-down box at the top of the properties sheet.
2. Experiment with changing properties in these two property groups:
GridControl->Features—the formula engine related features
GridControl->Param—the Excel-like features
3. Experiment with changing other grid-wide properties, such as the number of row and columns in the grid, background color, default column width, layout and appearance, behavior, and accessibility.
Setting Cell Properties
1. Experiment with the GridControl->CurrentCell property group. This group allows you to set properties for the selected cell. The properties of a cell are determined by the style object contained by the cell.