Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Understanding the Underlying Models / Understanding the Sheet Model Classes and Interfaces / Understanding the Data Model
In This Topic
    Understanding the Data Model
    In This Topic

    The data model includes the contents of the cells, including the value or the formula in a cell, and the cell notes or cell tags. This includes the Value properties for cells in the data area of the spreadsheet, the database properties for data-bound spreadsheets, and anything having to do with the contents in the cells.

    You are likely to customize the data model when working with Spread. The data model implements more interfaces, and more optional functionality through it, than any of the other models. Also, if you want to implement the equivalent to the unbound virtual model feature of the ActiveX Spread control, for example, you will need to customize the data model.

    The following topics provide more information about the data model:

    For more details, refer to the BaseSheetDataModel class, the DefaultSheetDataModel class and the ISheetDataModel interface.

    Data Model Object

    The data model is an object that supplies the cell values being displayed in the sheet. In most cases, you can simply use the default data model of Spread that is created when the sheet is created.

    The default data model of Spread creates objects to store notes, formulas, tags, and values, and those objects are designed to balance memory usage versus speed based on how big the model is and how sparse the data in the model is. If you are not using notes, formulas, and tags, then the component does not use much memory because the data is fairly sparse. In fact, those objects do not allocate any memory for data until it is actually needed; therefore, as long as there are no notes, formulas, or tags set in the model, memory usage remains low.

    The default data model can be used in unbound mode or bound mode. In unbound mode, the data model acts similarly to a two-dimensional array of cell values. In bound mode, the data model wraps the supplied data source and if needed can supply additional settings not available from the data source, for example, cell formulas and unbound rows or columns.

    Setting and Adding to the Data Model

    The SetModelDataColumn is different from AddColumn in that you can specify which data field you want bound to which column in the data model.

    If you add columns to the model, then they are added to the sheet. The row and column in the GetValue and SetValue methods of the data model have the same indexes as that of the columns in the sheet as long as the sheet is not sorted. If the sheet's rows or columns are sorted, then the view coordinates must be mapped to the model coordinates with these SheetView.GetModelRowFromViewRow and SheetView.GetModelColumnFromViewColumn methods.

    The SheetView.GetValue and SheetView.SetValue methods always get and set the data in the data model. Calling these methods is the same as calling SheetView.Models.Data.GetValue and SheetView.Models.Data.SetValue. The Cell.Value property returns the value of the cell in the editor control if the cell is currently in edit mode in a SpreadView containing the SheetView. That value is not updated to the data model until the cell leaves edit mode; however, you can manually update the value in the data model using code:

    C#
    Copy Code
    SheetView.SetValue(row, column, SheetView.Cells(row, column).Value);
    

    Implemented Interfaces

    When the data model implements IDataSourceSupport and it is bound to a data source, the bound parts of the data model get and set data directly from the data source. Some columns in a bound data model can be unbound if columns are added to the data model with AddColumns after it is bound (IDataSourceSupport.IsColumnBound returns False for those model column indexes), and the values in those unbound columns are stored in the data model rather than the data source.

    If the data model also implements IUnboundRowSupport, then some rows in the data model can also be unbound, and those values are also stored in the data model rather than the data source. Such rows can be made into bound rows by calling IUnboundRowSupport.AddRowToDataSource, and if the autoFill parameter is specified as True, then the data in the bound columns in that unbound row will be added to the data source in a new record or element, assuming that the data source permits it (you will get an exception if it does not), and the unbound row becomes a bound row.

    The default data model class, DefaultSheetDataModel, implements all of these interfaces, plus many others related to calculation, hierarchy, and serialization.

    See Also