Back to Devexpress

SvgImageBox.SelectionChanging Event

windowsforms-devexpress-dot-xtraeditors-dot-svgimagebox-038e2938.md

latest3.7 KB
Original Source

SvgImageBox.SelectionChanging Event

Fires when the item selection is about to be changed. Allows you to cancel the current operation.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
public event SvgImageSelectionChangingEventHandler SelectionChanging
vb
Public Event SelectionChanging As SvgImageSelectionChangingEventHandler

Event Data

The SelectionChanging event's data class is SvgImageSelectionChangingEventArgs. The following properties provide information specific to this event:

PropertyDescription
ActionGets or sets how the selected item collection has been changed.
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
ItemGets or sets the currently processed item.

Remarks

The event’s Item parameter specifies the item whose selected state is about to be changed. Use the Action parameter to identify the item’s new state.

If all items are deselected at once (the SvgImageBox.Selection collection is cleared), the Item parameter returns null and the Action parameter returns Clear.

To prevent an item’s selected state from being changed, set the event’s Cancel parameter to true.

Example

This example shows how to handle the SelectionChanging event to prevent the current selection from being changed.

csharp
private void svgImageBox1_SelectionChanging(object sender, DevExpress.XtraEditors.SvgImageSelectionChangingEventArgs e) {
    //Prevent item selection from being cleared when a user clicks on the empty space
    if (e.Action == DevExpress.XtraEditors.SvgImageSelectionChangeAction.Clear) {
        e.Cancel = true;
        return;
    }

    //Prevent an item from being selected/deselected.
    if (e.Item == svgImageBox1.HoveredItem) {
        e.Cancel = true;
        return;
    }
}
vb
Private Sub SvgImageBox1_SelectionChanging(sender As Object, e As DevExpress.XtraEditors.SvgImageSelectionChangingEventArgs) Handles SvgImageBox1.SelectionChanging
    'Prevent item selection from being cleared when a user clicks on the empty space
    If e.Action = DevExpress.XtraEditors.SvgImageSelectionChangeAction.Clear Then
        e.Cancel = True
        Return
    End If
    'Prevent an item from being selected/deselected.
    If e.Item.Equals(SvgImageBox1.HoveredItem) Then
        e.Cancel = True
        Return
    End If
End Sub

See Also

SvgImageBox Class

SvgImageBox Members

DevExpress.XtraEditors Namespace