Cells and Cell Ranges
- 3 minutes to read
All worksheet data is stored in cells (Worksheet.Cells). All cells have faint borders around them, which are called gridlines. You can display or hide gridlines programmatically using the WorksheetView.ShowGridlines property. To enable end-users to change the visibility of gridlines, add the Show Ribbon page group to the SpreadsheetControl. For an example on how to provide the Ribbon UI for the SpreadsheetControl, see the Getting Started topic.
An individual cell is a box at the intersection of a column and row. Each cell is indicated by a cell reference - the column letter and row number where the column and row intersect. The SpreadsheetControl supports different cell reference styles and types. The cell reference is displayed in the Name Box, usually located at the top-left corner of a worksheet. Besides the cell address, the control also displays defined names, specified in a worksheet. End-users can use the Name Box to navigate to different cells in a worksheet. To provide end-users with the capability to use the Name Box, add the control directly from the DX.19.1: Spreadsheet Toolbox tab or select the Create FormulaBar item in the SpreadsheetControls Tasks menu to automatically add the Name Box control above the spreadsheet work area. For an example on how to create the Name Box for the SpreadsheetControl, refer to the Getting Started topic.
The SpreadsheetControl.GetCellBounds method allows you to obtain a cell’s x- and y-coordinates relative to the SpreadsheetControl’s top-left corner, and the cell’s width and height
The current cell that is selected and used to enter data is called the active cell. The active cell is identified by a blue border around the cell. To specify the active cell in code, use the SpreadsheetControl.ActiveCell, SpreadsheetControl.SelectedCell or Worksheet.SelectedCell property. When a cell range (Worksheet.Range) is selected, the active cell is usually the top left cell of the selected range. However, end-users can specify the position of the active cell by pressing TAB, SHIFT+TAB, ENTER or SHIFT+ENTER (for more information about supported shortcuts, refer to the Work with Selections document). To get or set the selected cell range, use the SpreadsheetControl.Selection or Worksheet.Selection property. To select multiple non-adjacent cells or cell ranges, use the SpreadsheetControl.SetSelectedRanges or Worksheet.SetSelectedRanges method. To obtain a list of selected cell ranges, use the SpreadsheetControl.GetSelectedRanges or Worksheet.GetSelectedRanges method.
You can also prevent end-users from selecting multiple cell ranges in a worksheet by setting the SpreadsheetSelectionOptions.AllowMultiSelection property to false. Note that this option does not affect multi-selection in code.