Back to Devexpress

TdxSpreadSheetTableViewSelection.Items Property

vcl-dxspreadsheetcore-dot-tdxspreadsheettableviewselection-168d0184.md

latest3.4 KB
Original Source

TdxSpreadSheetTableViewSelection.Items Property

Provides indexed access to selected cell ranges.

Declaration

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

Property Value

TypeDescription
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):

delphi
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;
cpp
TdxSpreadSheetTableView *ATableView;
  TdxSpreadSheetCell *ACell;
  // ...
  ATableView = dxSpreadSheet1->ActiveSheetAsTable;
  ATableView->BeginUpdate(); // Starts the following batch change at the worksheet level
  try
  {
    for (int i = 0; i < ATableView->Selection->Count; i++) // Iterates through all selected cell ranges
    {
      // Iterates through all cell rows within the current cell range
      for (int j = ATableView->Selection->Items[i].Top; j <= ATableView->Selection->Items[i].Bottom; j++)
      {
        // Iterates through all cells within the current row
        for (int k = ATableView->Selection->Items[i].Left; k <= ATableView->Selection->Items[i].Right; k++)
        {
          ACell = ATableView->CreateCell(j, k);
          ACell->Style->Brush->BackgroundColor = clYellow;
        }
      }
    }
  }
  __finally
  {
    ATableView->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }

See Also

TdxSpreadSheetTableViewSelection.Count Property

TdxSpreadSheetTableViewSelection Class

TdxSpreadSheetTableViewSelection Members

dxSpreadSheetCore Unit