# Events

This topic describes the events you can use in RadSpreadsheet so you can get a notification about different actions.

## RadSpreadsheet Events

* `ActiveSheetChanged`—Occurs when the active sheet is changed.

* `ActiveSheetEditorChanged`—Occurs when the active sheet editor is changed.

* `MessageShowing`—Occurs when the user is presented with a warning message. The event arguments are of type `MessageShowingEventArgs` and expose the following properties:

  * `IsHandled`—Gets or sets whether the event is handled.
  * `Header`—Gets or sets the header of the message.
  * `Content`—Gets or sets the content of the message.
  * `NotificationType`—Gets or sets the type of the notification. The property is of type [MessageBoxNotificationType](https://docs.telerik.com/devtools/wpf/api/telerik.windows.controls.spreadsheet.dialogs.messageboxnotificationtype).

  **Disable messages related to protection using the MessageShowing event**

  ```C#

  public void AttachToMessageShowingEvent()
  {
      this.radSpreadsheet.MessageShowing += radSpreadsheet_MessageShowing;
  }

  private void radSpreadsheet_MessageShowing(object sender, Telerik.Windows.Controls.Spreadsheet.MessageShowingEventArgs e)
  {
      if (e.NotificationType == Telerik.Windows.Controls.Spreadsheet.Dialogs.MessageBoxNotificationType.ProtectedWorksheetError)
      {
          e.IsHandled = true;
      }
  }
  ```

  ```VB.NET
  	    Public Sub AttachToMessageShowingEvent()
  	        AddHandler Me.radSpreadsheet.MessageShowing, AddressOf radSpreadsheet_MessageShowing
  	    End Sub
  	
  	    Private Sub radSpreadsheet_MessageShowing(sender As Object, e As Telerik.Windows.Controls.Spreadsheet.MessageShowingEventArgs)
  	        If e.NotificationType = Telerik.Windows.Controls.Spreadsheet.Dialogs.MessageBoxNotificationType.ProtectedWorksheetError Then
  	            e.IsHandled = True
  	        End If
  	    End Sub
  ```

* `WorkbookCommandError`—Notifies that an error occurred while executing a command in RadSpreadsheet. The arguments are of type `CommandErrorEventArgs` and you can use the `Exception` property to check what exactly the error is.

* `WorkbookChanging`—Occurs when the workbook starts changing.

* `WorkbookChanged`—Occurs when the workbook is changed.

* `WorkbookCommandExecuting`—Occurs when workbook command starts executing. The arguments are of type [CommandExecutingEventArgs](https://docs.telerik.com/devtools/wpf/api/telerik.windows.documents.spreadsheet.commands.commandexecutingeventargs) and allow you to cancel the execution of the command.

  **Cancel a command through WorkbookCommandExecuting**

  ```C#
  private void radSpreadsheet_WorkbookCommandExecuting(object sender, Telerik.Documents.Spreadsheet.Commands.CommandExecutingEventArgs e)
  {
      if (e.CommandName == "AddShapeCommand")
      {
          e.Cancel();
      }
  }
  ```

  ```VB.NET
  	    Public Sub AttachToWorkbookCommandExecutingEvent()
  	        AddHandler Me.radSpreadsheet.WorkbookCommandExecuting, AddressOf radSpreadsheet_WorkbookCommandExecuting
  	    End Sub
  	
  	    Private Sub radSpreadsheet_WorkbookCommandExecuting(sender As Object, e As Telerik.Windows.Documents.Spreadsheet.Commands.CommandExecutingEventArgs)
  	        If e.CommandName = "AddShapeCommand" Then
  	            e.Cancel()
  	        End If
  	    End Sub
  ```

* `WorkbookCommandExecuted`—Occurs when workbook command is executed.

* `WorkbookContentChanged`—Occurs when the content of the workbook is changed.

## Workbook Events

* `ActiveSheetChanged`—Occurs when the active sheet is changed.

* `WorkbookContentChanged`—Occurs when the workbook content is changed.

* `IsProtectedChanged`—Occurs when the current protection state has changed.

* `NameChanged`—Occurs when the name of the workbook is changed.

* `ThemeChanged`—Occurs when a theme is changed.

## Worksheet Events

* `IsProtectedChanged`—Occurs when the current protection state has changed.

* `LayoutInvalidated`—Occurs when the layout is invalidated.

* `NameChanged`—Occurs when the name of the worksheet is changed.

## RadWorksheetEditor Events

* `PreviewSheetChanging`—Occurs just before the sheet changing begins.

* `SheetChanging`—Occurs when the sheet is changing.

* `PreviewSheetChanged`—Occurs just before the sheet changing ends.

* `SheetChanged`—Occurs when the sheet is already changed.

* `ScaleFactorChanged`—Occurs when the scale factor is changed.

* `UICommandExecuting`—Occurs when a UI command is executing. Using the event arguments, you can obtain the command that is going to be executed with its parameters.

* `UICommandExecuted`—Occurs when the UI command is executed. Using the event arguments, you can obtain the command that was executed with its parameters.

* `UICommandError`—Occurs on UI command error. The event args expose the Exception property, which can help you get the error that was thrown.

* `ScrollModeChanged`—Occurs when the scroll mode is changed.

* `ActivePresenterChanged`—Occurs when the active presenter is changed.

* `HyperlinkClicked`—Occurs when a hyperlink in the document gets clicked. The event allows you to cancel or replace the navigation logic.

  **Using the HyperlinkClicked to implement extra confirmation for the links in the document**

  ```C#
  private void RadSpreadsheet_ActiveSheetEditorChanged(object sender, EventArgs e)
  {
      RadWorksheetEditor editor = (RadWorksheetEditor)this.radSpreadsheet.ActiveSheetEditor;
      editor.HyperlinkClicked += this.RadWorksheetEditor_HyperlinkClicked;
  }

  private void RadWorksheetEditor_HyperlinkClicked(object sender, Telerik.Windows.Controls.Spreadsheet.Worksheets.MouseHandlers.HyperlinkClickedEventArgs e)
  {
      if (e.Url.EndsWith("exe"))
      {
          e.Handled = true;
          MessageBoxResult Result = MessageBox.Show("You are about to open an executable file. Do you want to proceed?", "Possible unsafe link", MessageBoxButton.YesNo, MessageBoxImage.Question);

          if (Result == MessageBoxResult.Yes)
          {
              Process.Start(new ProcessStartInfo()
              {
                  FileName = e.Url,
                  UseShellExecute = true
              });
          }
      }
  }
  ```

  The `HyperlinkClickedEventArgs` exposes `Url`, `IsTrustedUrl`, `Handled`, and `CellIndex`. Set `Handled` to `true` to cancel the default action. External-link validation already existed; this change adds the shared `HyperlinkManager.HyperlinkClicked` event. The shared event runs after the editor-specific event if the editor event does not handle the request.

  The cell clicked to open the hyperlink can be accessed with the `CellIndex` property of `HyperlinkClickedEventArgs`.

  **Accessing the CellIndex of the clicked cell**

  ```C#
  private void RadWorksheetEditor_HyperlinkClicked1(object sender, Telerik.Windows.Controls.Spreadsheet.Worksheets.MouseHandlers.HyperlinkClickedEventArgs e)
  {
      CellIndex cellIndex = e.CellIndex;
  }
  ```

  For an internal hyperlink, setting `Handled` to `true` prevents both the worksheet switch and the selection of the target cell. The editor raises its hyperlink event before either action.

  For external URLs, absolute HTTP, HTTPS, and mailto URLs can be trusted by default when they pass the validator's pattern and scheme checks. Set `IsTrustedUrl` to `true` in the editor-specific or shared event to allow the default launch of a URL the validator would otherwise reject. The shared event's `sender` depends on the originating control or component.

  `HyperlinkManager.HyperlinkClicked` is static. Unsubscribe handlers when their owners are shorter-lived than the application. See [Handling hyperlink navigation in RadHyperlinkButton](https://www.telerik.com/products/wpf/documentation/controls/radbuttons/features/hyperlink-button) for a shared-event example.

> The events related to selection in RadSpreadsheet are described in the [Working with UI Selection](https://www.telerik.com/products/wpf/documentation/controls/radspreadsheet/ui-working-with-selection) topic.

## Cells Events

* `CellPropertyChanged`—Occurs when a property of a cell is changed. The event arguments are of type **CellPropertyChangedEventArgs** and expose information about the exact property that was changed as well as the affected cell range.

  **Using the CellPropertyChangedEvent to show a notification when the users change the fill of a cell**

  ```C#
  public void AttachToCellPropertyChangedEvent()
  {
      this.radSpreadsheet.ActiveWorksheet.Cells.CellPropertyChanged += Cells_CellPropertyChanged;
  }

  private void Cells_CellPropertyChanged(object sender, CellPropertyChangedEventArgs e)
  {
      if (e.Property == CellPropertyDefinitions.FillProperty)
      {
          MessageBox.Show("The fill of a cell was changed!");
      }
  }
  ```

  ```VB.NET
  	    Public Sub AttachToCellPropertyChangedEvent()
  	        AddHandler Me.radSpreadsheet.ActiveWorksheet.Cells.CellPropertyChanged, AddressOf Cells_CellPropertyChanged
  	    End Sub
  	
  	    Private Sub Cells_CellPropertyChanged(sender As Object, e As CellPropertyChangedEventArgs)
  	        If e.Property = CellPropertyDefinitions.FillProperty Then
  	            MessageBox.Show("The fill of a cell was changed!")
  	        End If
  	    End Sub
  ```

* `CellRangeInsertedOrRemoved`—Occurs when a cell range is inserted or removed. Through the arguments, you can obtain information about the affected ranges, as well as whether the range is removed or not.

* `MergedCellsChanged`—Occurs when the merged cells collection in a worksheet is changed. The MergedCellRangesChangedEventArgs class represents the event arguments and holds the cell range related to the change.

## Row/Column Events

* `ColumnsWidthChanged`—Occurs when the columns' widths are changed.

* `RowsHeightsChanged`—Occurs when the rows' heights are changed.

The arguments of the two events are of type `RowColumnPropertyChangedEventArgs` and expose the following properties:

* `Property`—Gets the property that was changed.
* `FromIndex`—Gets the first index of the changed range.
* `ToIndex`—Gets the last index of the changed range.

## See Also

* [Model](https://www.telerik.com/products/wpf/documentation/controls/radspreadsheet/getting-started#model)
* [Telerik UI for WPF API Reference](https://docs.telerik.com/devtools/wpf/api/)
