Skip to main content

Understanding Views

  • 5 minutes to read

The most important part of the Spreadsheet control is the scrollable View area designed to display a portion of the currently active worksheet. Unlike other visual elements of the control, the View cannot be hidden and occupies the major portion of the control’s area.

In terms of code, individual sheets within the currently active workbook are called “Views”. Since many popular spreadsheet applications provide more than one worksheet type (such as the plain table view with editable cells (Table View), the Print Preview (Print View), Chart View, Pivot View, etc.), the Spreadsheet Control’s API employs the unified approach to workbook sheets (or View worksheets). There are two levels of accessing individual worksheets:

  • Generalized worksheet access (the Custom View worksheets) allows you to customize settings that are common to all supported actual worksheet types, such as the caption, visibility, or the containers collection. The Spreadsheet control provides the ActiveSheet, Sheets and VisibleSheets properties that provide you generalized access to individual sheets within the currently opened spreadsheet document. TdxSpreadSheetCustomView objects, referenced by these properties, do not correspond to actual worksheets.

  • Actual worksheet access (the Specific View worksheets) allows you to modify properties and settings, specific to certain worksheet types that can actually be created, manipulated, and destroyed within the Spreadsheet control. Actual worksheet types are descendants of the TdxSpreadSheetCustomView class. Currently, the Spreadsheet control provides the Table View worksheets (implemented as TdxSpreadSheetTableView objects). To access Table View worksheets in the Spreadsheet control, use either its ActiveSheetAsTable property or cast the objects returned by the Sheets and VisibleSheets properties to the TdxSpreadSheetTableView type.

Custom View Worksheets

The Custom View is a “generic” form of a worksheet. The ActiveSheet, Sheets, and VisibleSheets properties provide unified access to individual worksheets regardless of their type (including custom worksheet types). The “generic access” to worksheets allows you to customize their displayed caption, visibility flags, container collections, etc.

To access the type-specific worksheet properties and methods, you should cast a Custom View object to the required Specific View type (the TdxSpreadSheetCustomView descendant). Make sure that the type to which you are going to cast the Custom View, matches the type of worksheet you actually created.

//...
var
  ATableView: TdxSpreadSheetTableView;
  ASheet: TdxSpreadSheetCustomView;
//...
// Creating the worksheet with a distinctive name
  dxSpreadSheet1.AddSheet('Worksheet Table View', TdxSpreadSheetTableView);
// Using the name to obtain the sheet we have created
  ASheet := dxSpreadSheet1.GetSheetByName('Worksheet Table View');
// Checking whether the created worksheet is actually a Table View
  if(ASheet.ClassName = 'TdxSpreadSheetTableView') then
    ATableView := TdxSpreadSheetTableView(ASheet);  // Casting the generic worksheet to the Table View type

For more information on managing worksheets and their basic properties, refer to the Worksheet Management topic.

Table View Worksheets

Table View worksheets are TdxSpreadSheetTableView objects that you can use to list, sort, and analyze your data stored within the cells, arranged into the logical rows and columns. A newly created Table View worksheet has no cell, row and/or column objects designed to store both data and custom appearance and behavior settings:

You can access the currently active Table View sheet within the current workbook by using the Spreadsheet Control’s ActiveSheetAsTable property:

//...
var
  ActiveTableView, TableView1: TdxSpreadSheetTableView;
//...
  ActiveTableView := dxSpreadSheet1.ActiveSheetAsTable;  // Accessing the currently active worksheet within a workbook
  TableView1 := TdxSpreadSheetTableView(dxSpreadSheet1.Sheets[1]);  // Accessing the second spreadsheet within a workbook

For a more unified access to Table View worksheets within the current spreadsheet document, you need to cast TdxSpreadSheetCustomView objects returned by the Sheets and VisibleSheets properties to the TdxSpreadSheetTableView type:

//...
var
  ATableView1, ATableView2: TdxSpreadSheetTableView;
  AIndex: Integer;
//...
// Obtaining the index of the active worksheet
  AIndex := dxSpreadSheet1.ActiveSheetIndex;
// Accessing the active Table View via the ActiveSheet property
  ATableView1 := TdxSpreadSheetTableView(dxSpreadSheet1.ActiveSheet);
// Accessing the active Table View by the active worksheet index
  ATableView2 := TdxSpreadSheetTableView(dxSpreadSheet1.Sheets[AIndex]);

Zooming Worksheets

A worksheet displayed by the Spreadsheet control can be zoomed in or out. To zoom the worksheet content in or out, use the Table View worksheet’s Options.ZoomFactor property. An end-user can zoom the currently active sheet by scrolling the mouse wheel while holding the Ctrl key.

The image below demonstrates the upper and lower limits of Table View worksheet zooming in comparison with the sheet’s original (real) size.

Refer to the following topics for more information on working with Table View worksheets: