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

TdxSpreadSheetChangeFillColor Class

An action object that implements the ChangeFillColor end-user command in Spreadsheet and Report Designer-based applications.

#Declaration

Delphi
TdxSpreadSheetChangeFillColor = class(
    TdxSpreadSheetValueAction,
    IdxActionColorValue
)

#Remarks

This class does not introduce any new public members. The TdxSpreadSheetChangeFillColor action object is designed to be used in a Ribbon or Toolbar UI by the following item controls:

TcxColorComboBox
Represents a color combo box control.
TdxRibbonColorGalleryItem
A bar item that provides advanced color selection capabilities.

VCL SpreadSheet: A Ribbon Color Gallery Item

A color picked by an end-user via a TcxBarEditItem UI element is automatically applied to all selected cells as their background color.

VCL SpreadSheet: A Change Fill Color Example

If you need to link a TdxSpreadSheetChangeFillColor action object to a custom client control, re-implement the action’s functionality in its OnExecute event handler. Otherwise, executing this action object via custom client controls has no effect.

In order to re-implement the functionality of a TdxSpreadSheetChangeFillColor action object for linking it to a custom client control, refer to the following code example:

procedure TSpreadSheetControlForm.dxSpreadSheetChangeFillColor1Execute(Sender: TObject);
var
  ATableView: TdxSpreadSheetTableView;
  ACell: TdxSpreadSheetCell;
  I, J, K: Integer;  // Counters
begin
  ATableView := dxSpreadSheet1.ActiveSheetAsTable;
  if(ATableView.Selection.Count > 0) then
  begin
    ATableView.BeginUpdate;  // Stops worksheet repainting until the new background color is applied to all affected cells
    for I := 0 to ATableView.Selection.Count - 1 do  // Cycles through all selected cell ranges
      for J := ATableView.Selection.Items[I].Left to ATableView.Selection.Items[I].Right do  // Cycles through all columns within one selected cell area
        for K := ATableView.Selection.Items[I].Top to ATableView.Selection.Items[I].Bottom do  // Cycles through all rows within one selected cell area
        begin
          ACell := ATableView.CreateCell(K, J);  // Obtains every cell object within one selected area
          ACell.Style.Brush.BackgroundColor := clRed;  // Here you can specify any color instead of red
        end;
    ATableView.EndUpdate;  // Enables worksheet repainting to display the pending changes
  end;
end;

UI elements linked to a TdxSpreadSheetChangeFillColor action object are enabled only if the following conditions are met:

If no cells can be selected in the protected worksheet (i.e., its OptionsProtection.ActualAllowSelectUnlockedCells property returns False), executing the TdxSpreadSheetChangeFillColor action object has no effect.

See Also