Spread Windows Forms 6.0 Product Documentation
Creating a Custom Sheet Model
Support Options
Spread Windows Forms 6.0 Product Documentation > Developer's Guide > Understanding the Underlying Models > Creating a Custom Sheet Model

Glossary Item Box

You can use a sheet model as a template for a new custom model. For example, consider making a custom data model. Using a custom data model requires creating a class which implements ISheetDataModel, then setting an instance of the class into the SheetView.Models.Data property.

ISheetDataModel is the only interface required, assuming that you do not need any of the optional interfaces. For more information on the other interfaces, refer to Understanding the Optional Interfaces.

All of the optional interfaces are implemented by DefaultSheetDataModel, so if you want any of them implemented on your data model, it may be easier to simply subclass DefaultSheetDataModel.

In BaseSheetDataModel, the Changed event is also implemented.

There is an example of a custom data model in the product samples, in the Samples\CS\FreeCell folder. It is an implementation of the game FreeCell inside a data model.

Return to the overview of Understanding the Underlying Models.

In a few cases, you may need to create your own custom data model for performance reasons. For example, suppose you want to display a large table of computed values (such as an addition or multiplication table) that consists of a million rows by ten columns. If you used the default sheet data model, you would need to compute and store all ten million values which would be consume a lot of time and memory. Here is the example code.

Example

C# Copy Code
for (r = 0; r < 1000000; r++) 

for ( c = 0; c < 10; c++) 

spread.Sheets[0].Cells[r,c].Value = r + c;
 

Example

C# Copy Code
class ComputedDataModel : BaseSheetDataModel 

{ 

    public override int RowCount 

    { 

        get { return 1000000; } 

    } 

    public override int ColumnCount 

    { 

        get { return 10; } 

    } 

    public override object GetValue(int row, int column) 

    { 

        return row + column; 

    } 

} 

© 2002-2012 ComponentOne, a division of GrapeCity. All Rights Reserved.