Skip to main content

TdxSpreadSheetTableViewSelection.Count Property

Returns the number of individual selected cell ranges.

Declaration

property Count: Integer read;

Property Value

Type Description
Integer

The total number of selected individual cells and separate cell ranges.

Remarks

Use the Count property to identify the number of cell ranges accessible through the Items property. The Count property returns 0 if no cell is selected in the active worksheet (for example, if a floating container has focus).

Code Example: Apply Custom Formatting to All Selected Cells

The following code example fills the background of all selected cells with yellow (the clYellow color value):

var
  ATableView: TdxSpreadSheetTableView;
  ACell: TdxSpreadSheetCell;
  I, J, K: Integer;
begin
  ATableView := dxSpreadSheet1.ActiveSheetAsTable;
  ATableView.BeginUpdate; // Starts the following batch change at the worksheet level
  try
    for I := 0 to ATableView.Selection.Count - 1 do // Iterates through all selected cell ranges
    begin
      // Iterates through all cell rows within the current cell range
      for J := ATableView.Selection.Items[I].Top to ATableView.Selection.Items[I].Bottom do
      begin
        // Iterates through all cells within the current row
        for K := ATableView.Selection.Items[I].Left to ATableView.Selection.Items[I].Right do
        begin
          ACell := ATableView.CreateCell(J, K);
          ACell.Style.Brush.BackgroundColor := clYellow;
        end;
      end;
    end;
  finally
    ATableView.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
  end;
end;

VCL Spreadsheet: A Highlight Cell Selection Example

See Also