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

TdxCustomSpreadSheet.OnSelectionChanged Event

In This Article

Enables you to respond to any changes made to the worksheet content selection.

#Declaration

Delphi
property OnSelectionChanged: TNotifyEvent read; write;

#Remarks

This event occurs every time:

Use the Sender parameter to refer to the worksheet that raised the event. Cast the parameter to its actual type (TdxSpreadSheetTableView, for instance) to access worksheet’s properties and methods. The OnSelectionChanged event is particularly useful if you need to implement the custom spreadsheet content protection mechanism, such as preventing only certain columns or rows from accidental modifications. The following code example shows how to prevent value editing in any cell within the second (that is, B) worksheet column.

TMySpreadSheetForm.dxSpreadSheet1SelectionChanged(Sender: TObject);
var
  ATableView: TdxSpreadSheetTableView;
begin
  ATableView := Sender as TdxSpreadSheetTableView;  // Casts the Sender parameter to the actual worksheet type to make its members accessible
  if ATableView.Selection.FocusedColumn = 1 then  // Specifies the worksheet content protection conditions (that is, the required selection state)
    ATableView.OptionsProtection.&Protected := True  // Enables protection
  else  // If the specified worksheet protection conditions are not met...
    ATableView.OptionsProtection.&Protected := False;  // Disables protection
end;

Refer to the Worksheet Protection topic for detailed information on the worksheet protection mechanism provided by the Spreadsheet and Report Designer controls out-of-the-box.

See Also