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

TdxSpreadSheetChangeFontName Class

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

#Declaration

Delphi
TdxSpreadSheetChangeFontName = class(
    TdxSpreadSheetValueAction,
    IdxActionFontNameValue
)

#Remarks

This class does not introduce any new public members. The command implemented as a TdxSpreadSheetChangeFontName action object is designed for use in a Ribbon or Toolbar UI by a TcxFontNameComboBox item control.

VCL SpreadSheet: A Font Name Combo Box

Executing a TdxSpreadSheetChangeFontName action object by clicking an item in the linked TcxFontNameComboBox UI element changes the font typeface used to display:

  • The values in all selected cells.
  • The text selection within an in-place cell editor (only if the rich content formatting functionality is enabled in the Spreadsheet/Report Designer control).

VCL SpreadSheet: A Change Font Name Example

Handle the TdxSpreadSheetChangeFontName action object’s OnExecute event to provide custom implementation of the ChangeFontName command’s functionality, which is useful if you need to use it with a custom client control instead of TcxFontNameComboBox. Refer to the following code example re-implementing the command’s capability to apply a specific font typeface to the current cell selection:

procedure TSpreadSheetControlForm.dxSpreadSheetChangeFontName1Execute(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 font typeface 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.Font.Name := 'Times New Roman';  // Here you can specify any font typeface instead of Times New Roman
        end;
    ATableView.EndUpdate;  // Enables worksheet repainting to display the pending changes
  end;
end;

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

If cell selection is disallowed in the protected worksheet (that is, its OptionsProtection.ActualAllowSelectUnlockedCells property returns False), executing the TdxSpreadSheetChangeFontName action object has no effect.

See Also