NamedRange.Deselected Event (2007 System)
Occurs when selection moves from the NamedRange control to an area outside of the NamedRange control.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)
Syntax
'Declaration
Public Event Deselected As DocEvents_SelectionChangeEventHandler
'Usage
Dim instance As NamedRange
Dim handler As DocEvents_SelectionChangeEventHandler
AddHandler instance.Deselected, handler
public event DocEvents_SelectionChangeEventHandler Deselected
public:
event DocEvents_SelectionChangeEventHandler^ Deselected {
void add (DocEvents_SelectionChangeEventHandler^ value);
void remove (DocEvents_SelectionChangeEventHandler^ value);
}
JScript does not support events.
Remarks
This event is raised only when the NamedRange control has focus, and then focus is transferred away from the NamedRange control.
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.
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
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(missing, missing,
Excel.XlReferenceStyle.xlA1, missing, missing);
MessageBox.Show("The NamedRange control was deselected." +
" Selection transferred to " + this.Name + ":" +
targetRange + ".");
}
This version is for an application-level add-in.
Private deselectedRange As NamedRange
Private Sub DeselectRange()
Dim vstoWorksheet As Worksheet = CType( _
Me.Application.ActiveWorkbook.Worksheets(1), _
Excel.Worksheet).GetVstoObject()
deselectedRange = vstoWorksheet.Controls.AddNamedRange( _
vstoWorksheet.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, , )
System.Windows.Forms.MessageBox.Show( _
"The NamedRange control was deselected." & _
" Selection transferred to " & _
Me.Application.ActiveWorkbook.Worksheets(1).Name & ":" & _
targetRange & ".")
End Sub
NamedRange deselectedRange;
private void DeselectRange()
{
Worksheet vstoWorksheet = ((Excel.Worksheet)
this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
deselectedRange = vstoWorksheet.Controls.AddNamedRange(
vstoWorksheet.Range["B1", "D4"], "deselectedRange");
deselectedRange.Select();
deselectedRange.Deselected += new
Excel.DocEvents_SelectionChangeEventHandler(
deselectedRange_Deselected);
}
void deselectedRange_Deselected(Excel.Range Target)
{
string targetRange = Target.get_Address(missing, missing,
Excel.XlReferenceStyle.xlA1, missing, missing);
Excel.Worksheet nativeWorksheet = (Excel.Worksheet)
this.Application.ActiveWorkbook.Worksheets[1];
System.Windows.Forms.MessageBox.Show("The NamedRange control was deselected." +
" Selection transferred to " +
nativeWorksheet.Name + ":" +
targetRange + ".");
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.Office.Tools.Excel Namespace
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Added a version of the code example for an application-level add-in. |
SP1 feature change. |