ListObject.Selected 事件

当选择 ListObject 控件时发生。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)

语法

声明
Event Selected As DocEvents_SelectionChangeEventHandler
event DocEvents_SelectionChangeEventHandler Selected

备注

当所选内容更改为 ListObject 控件时,将引发此事件。

示例

下面的代码示例创建一个 ListObject,然后为 Selected 事件创建事件处理程序。若要测试此事件处理程序,请先确保 ListObject 处于未选定状态,然后选择它。

此版本针对的是文档级自定义项。

    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.");
}

此版本针对的是应用程序级外接程序。

WithEvents SelectedList As ListObject
Private Sub ListObject_Selected()
    Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
        Me.Application.Worksheets(1)
    Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
            Globals.Factory.GetVstoObject(NativeWorksheet)
    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 =
        Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]);
    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 安全性

请参见

参考

ListObject 接口

Microsoft.Office.Tools.Excel 命名空间