Export (0) Print
Expand All

ListObject.Deselected Event

Occurs when selection moves from the ListObject control to outside of the ListObject control.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

event DocEvents_SelectionChangeEventHandler Deselected

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

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.

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.

private void ListObject_Deselected()
{
    Worksheet vstoWorksheet =
       Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]);
    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.");
}

Show:
© 2015 Microsoft