Back to Devexpress

TdxSpreadSheetTableView.Selection Property

vcl-dxspreadsheetcore-dot-tdxspreadsheettableview-15a8c1db.md

latest4.4 KB
Original Source

TdxSpreadSheetTableView.Selection Property

Provides access to the collection of selected cell ranges and objects in the worksheet.

Declaration

delphi
property Selection: TdxSpreadSheetTableViewSelection read;

Property Value

TypeDescription
TdxSpreadSheetTableViewSelection

The collection of selected cell ranges and objects.

|

Remarks

Use the Selection property to access and manage selections in the worksheet.

Available Options

You can use the Selection.Items property to access all individual selected cell ranges by their indexes. Selection.Add, Selection.Clear, Selection.SelectAll, Selection.SelectCell, Selection.SelectColumns, and Selection.SelectRows methods allow you to select or deselect cell ranges and individual cells.

Refer to the TdxSpreadSheetTableViewSelection class description for detailed information on all available options.

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

TdxSpreadSheetTableView.Dimensions Property

TdxSpreadSheetTableView Class

TdxSpreadSheetTableView Members

dxSpreadSheetCore Unit