TdxCustomSpreadSheet.OnSelectionChanged Event
Enables you to respond to any changes made to the worksheet content selection.
Declaration
property OnSelectionChanged: TNotifyEvent read; write;
Remarks
This event occurs every time:
The cell focus moves within the active worksheet;
A floating container (including comments) is selected or deselected;
The collection of selected cells and cell ranges is modified.
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.