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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。