Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TdxSpreadSheetTableViewSelection.Items Property

Provides indexed access to selected cell ranges.

#Declaration

Delphi
property Items[Index: Integer]: TcxRect read; default;

#Property Value

Type Description
TcxRect

Cell range boundaries, in row and column indexes.

#Remarks

Use the Items property to identify individual selected cell ranges by their indexes. Cell range indexes reflect the order of selection (areas with lower indexes were selected earlier).

You can use the Count property to identify the number of cell ranges accessible through the Items property. Each cell range is a rectangle whose coordinates and dimensions match corresponding row and column indexes.

#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;

See Also