Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
SelectionChange Event

ListObject.SelectionChange Event

Occurs when the selection changes inside the ListObject control.

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

event DocEvents_SelectionChangeEventHandler SelectionChange

This event is raised when any selected range inside the ListObject changes.

This event is not raised when focus moves from inside a ListObject control to outside of the ListObject control. It is raised when focus moves from outside a ListObject control to the ListObject control.

The following code example creates a ListObject and then creates an event handler for the SelectionChange event. To test the event handler, select a cell in the ListObject and then select a different cell in the ListObject.

This version is for a document-level customization.

private void ListObject_SelectionChange()
{
    Microsoft.Office.Tools.Excel.ListObject list1 =
        this.Controls.AddListObject(
        this.Range["A1", "C4"], "list1");
    list1.SelectionChange += new Microsoft.Office.Interop.
        Excel.DocEvents_SelectionChangeEventHandler(
        list1_SelectionChange);
}

void list1_SelectionChange(Microsoft.Office.Interop.Excel.Range Target)
{
    MessageBox.Show("The selection in the list object has changed.");
}

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

private void ListObject_SelectionChange()
{
    Worksheet vstoWorksheet =
            Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]); ;
    ListObject list1 =
        vstoWorksheet.Controls.AddListObject(
        vstoWorksheet.Range["A1", "C4"], "list1");
    list1.SelectionChange += new 
        Excel.DocEvents_SelectionChangeEventHandler(
        list1_SelectionChange);
}

void list1_SelectionChange(Excel.Range Target)
{
    System.Windows.Forms.MessageBox.Show("The selection in the list object has changed.");
}

Show:
© 2015 Microsoft