SpreadsheetControl.SelectionChanged Event
Fires when the selection changes in an active worksheet.
Namespace: DevExpress.Xpf.Spreadsheet
Assembly: DevExpress.Xpf.Spreadsheet.v24.2.dll
NuGet Package: DevExpress.Wpf.Spreadsheet
#Declaration
public event EventHandler SelectionChanged
#Event Data
The SelectionChanged event's data class is EventArgs.
#Remarks
Handle the SelectionChanged event to perform any actions each time a user selects cells, rows, columns, or drawing objects in the SpreadsheetControl’s UI.
Set the SpreadsheetControlOptions.RaiseEventsOnModificationsViaAPI property to true to raise the SelectionChanged event when the selection is changed in code.
Use the following API members to specify the selection:
SpreadsheetControl.SelectedCell, Worksheet.SelectedCell - allow you to specify an active cell.
SpreadsheetControl.Selection, Worksheet.Selection - allow you to select the continuous cell range.
SpreadsheetControl.SetSelectedRanges, Worksheet.SetSelectedRanges - allow you to select multiple non-adjacent cell ranges.
Worksheet.SelectedChart - specifies the selected chart.
SpreadsheetControl.SelectedPicture, Worksheet.SelectedPicture - allow you to select a picture.
SpreadsheetControl.SelectedShape, Worksheet.SelectedShape - allow you to select a drawing object.
SpreadsheetControl.SetSelectedShapes, Worksheet.SetSelectedShapes - allow you to select multiple drawing objects.
#Example
The example below shows how to use the SelectionChanged event to calculate the average, count, numerical count and sum for non-empty selected cells.
spreadsheetControl1.SelectionChanged += (s, e) =>
{
int count = 0;
double sum = 0.0;
int numericCount = 0;
double average = 0.0;
Worksheet worksheet = spreadsheetControl1.ActiveWorksheet;
Range selectedCells = worksheet.Selection.Intersect(worksheet.GetDataRange());
if (selectedCells != null)
{
foreach (Cell cell in selectedCells.ExistingCells)
{
count++;
if (cell.Value.IsNumeric)
{
numericCount++;
sum += cell.Value.NumericValue;
}
}
}
if (numericCount > 0)
average = sum / numericCount;
};
#Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SelectionChanged event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.