Share via


ListObject.Deselected Event (2007 System)

Occurs when selection moves from the ListObject control to outside of the ListObject 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 ListObject 
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 ListObject control has focus, and then focus is transferred away from the ListObject control.

Examples

The following code example creates a ListObject and a Deselected event handler. When the ListObject is selected and then an object outside of the ListObject is selected, a message is displayed that indicates that the selection has changed.

This version is for a document-level customization.

WithEvents DeselectedList As Microsoft.Office.Tools.Excel.ListObject
Private Sub ListObject_Deselected()
    DeselectedList = Me.Controls.AddListObject( _
        Me.Range("A1", "C4"), "DeselectedList")
End Sub 

Sub List1_Deselected(ByVal Target As _
    Microsoft.Office.Interop.Excel.Range) Handles DeselectedList.Deselected
    MessageBox.Show("The list object is no longer selected.")
End Sub
private void ListObject_Deselected()
{
    Microsoft.Office.Tools.Excel.ListObject list1 = 
        this.Controls.AddListObject(
        this.Range["A1", "C4"], "list1");
    list1.Deselected += new 
        Microsoft.Office.Interop.Excel.
        DocEvents_SelectionChangeEventHandler(list1_Deselected);
}

void list1_Deselected(Microsoft.Office.Interop.Excel.Range Target)
{
    MessageBox.Show("List1 is no longer selected.");
}

This version is for an application-level add-in.

WithEvents DeselectedList As ListObject
Private Sub ListObject_Deselected()
    Dim vstoWorksheet As Worksheet = CType( _
        Me.Application.ActiveWorkbook.Worksheets(1),  _
        Excel.Worksheet).GetVstoObject()
    DeselectedList = vstoWorksheet.Controls.AddListObject( _
        vstoWorksheet.Range("A1", "C4"), "DeselectedList")
End Sub 

Sub List1_Deselected(ByVal Target As  _
    Microsoft.Office.Interop.Excel.Range) Handles DeselectedList.Deselected
    System.Windows.Forms.MessageBox.Show( _
        "The list object is no longer selected.")
End Sub
private void ListObject_Deselected()
{
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    ListObject list1 =
        vstoWorksheet.Controls.AddListObject(
        vstoWorksheet.Range["A1", "C4"], "list1");
    list1.Deselected += new
        Excel.DocEvents_SelectionChangeEventHandler(list1_Deselected);
}

void list1_Deselected(Microsoft.Office.Interop.Excel.Range Target)
{
    System.Windows.Forms.MessageBox.Show("List1 is no longer selected.");
}

.NET Framework Security

See Also

Reference

ListObject Class

ListObject Members

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.