Share via


ListObject.Selected Event (2007 System)

Occurs when the ListObject control is selected.

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

Syntax

'Declaration
Public Event Selected As DocEvents_SelectionChangeEventHandler
'Usage
Dim instance As ListObject 
Dim handler As DocEvents_SelectionChangeEventHandler 

AddHandler instance.Selected, handler
public event DocEvents_SelectionChangeEventHandler Selected
public:
 event DocEvents_SelectionChangeEventHandler^ Selected {
    void add (DocEvents_SelectionChangeEventHandler^ value);
    void remove (DocEvents_SelectionChangeEventHandler^ value);
}
JScript does not support events.

Remarks

This event is raised when the selection changes to the ListObject control.

Examples

The following code example creates a ListObject and then creates an event handler for the Selected event. To test the event handler, ensure that the ListObject is not selected, and then select it.

This version is for a document-level customization.

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

Sub List1_Selected(ByVal Target As _
    Microsoft.Office.Interop.Excel.Range) Handles SelectedList.Selected
    MessageBox.Show("The list object has been selected.")
End Sub
private void ListObject_Selected()
{
    Microsoft.Office.Tools.Excel.ListObject list1 =
        this.Controls.AddListObject(
        this.Range["A1", "C4"], "list1");

    list1.Selected += new Microsoft.Office.Interop.Excel.
        DocEvents_SelectionChangeEventHandler(list1_Selected);
}

void list1_Selected(Microsoft.Office.Interop.Excel.Range Target)
{
    MessageBox.Show("The list object has been selected.");
}

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

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

Sub List1_Selected(ByVal Target As  _
    Microsoft.Office.Interop.Excel.Range) Handles SelectedList.Selected
    System.Windows.Forms.MessageBox.Show("The list object has been selected.")
End Sub
private void ListObject_Selected()
{
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    ListObject list1 =
        vstoWorksheet.Controls.AddListObject(
        vstoWorksheet.Range["A1", "C4"], "list1");

    list1.Selected += new 
        Excel.DocEvents_SelectionChangeEventHandler(list1_Selected);
}

void list1_Selected(Excel.Range Target)
{
    System.Windows.Forms.MessageBox.Show("The list object has been 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.