Compartilhar via


NamedRange.Deselected Event

Definition

Occurs when selection moves from the NamedRange control to an area outside of the NamedRange control.

public:
 event Microsoft::Office::Interop::Excel::DocEvents_SelectionChangeEventHandler ^ Deselected;
event Microsoft.Office.Interop.Excel.DocEvents_SelectionChangeEventHandler Deselected;
member this.Deselected : Microsoft.Office.Interop.Excel.DocEvents_SelectionChangeEventHandler 
Event Deselected As DocEvents_SelectionChangeEventHandler 

Event Type

Examples

The following code example demonstrates a handler for the Deselected event that displays the address of the cell that the selection is transferred to.

This version is for a document-level customization.

Microsoft.Office.Tools.Excel.NamedRange deselectedRange;
private void DeselectRange()
{
    deselectedRange = this.Controls.AddNamedRange(
        this.Range["B1", "D4"], "deselectedRange");
    deselectedRange.Select();
    this.deselectedRange.Deselected += new
        Microsoft.Office.Interop.Excel.
        DocEvents_SelectionChangeEventHandler(
        deselectedRange_Deselected);
}

void deselectedRange_Deselected(Excel.Range Target)
{
    string targetRange = Target.get_Address(
        Excel.XlReferenceStyle.xlA1);

    MessageBox.Show("The NamedRange control was deselected." +
        " Selection transferred to " + this.Name + ":" + 
        targetRange + ".");
}
Private deselectedRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub DeselectRange()
    deselectedRange = Me.Controls.AddNamedRange( _
        Me.Range("B1", "D4"), "deselectedRange")
    deselectedRange.Select()
    AddHandler Me.deselectedRange.Deselected, _
        AddressOf deselectedRange_Deselected
End Sub


Sub deselectedRange_Deselected(ByVal Target As Excel.Range)
    Dim targetRange As String = Target.Address(, , _
        Excel.XlReferenceStyle.xlA1, , )

    MessageBox.Show("The NamedRange control was deselected." & _
        " Selection transferred to " & Me.Name & ":" & _
        targetRange & ".")
End Sub

Remarks

This event is raised only when the NamedRange control has focus, and then focus is transferred away from the NamedRange control.

Applies to