ListObject.Deselected 事件
當選取範圍從 ListObject 控制項移至 ListObject 控制項之外時發生。
命名空間: Microsoft.Office.Tools.Excel
組件: Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)
語法
'宣告
Event Deselected As DocEvents_SelectionChangeEventHandler
event DocEvents_SelectionChangeEventHandler Deselected
備註
只有當 ListObject 控制項擁有焦點時,才會引發這個事件,然後焦點會從 ListObject 控制項移開。
範例
下列程式碼範例會建立 ListObject 和 Deselected 事件處理常式。 當選取 ListObject 然後又選取 ListObject 之外的物件時,會顯示訊息,表示選取範圍已變更。
這是示範文件層級自訂的版本。
WithEvents DeselectedList As Microsoft.Office.Tools.Excel.ListObject
Private Sub ListObject_Deselected()
DeselectedList = Me.Controls.AddListObject( _
Me.Range("A1", "C4"), "DeselectedList")
End Sub
Sub List1_Deselected(ByVal Target As _
Microsoft.Office.Interop.Excel.Range) Handles DeselectedList.Deselected
MessageBox.Show("The list object is no longer selected.")
End Sub
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.");
}
這是示範應用程式層級增益集的版本。
WithEvents DeselectedList As ListObject
Private Sub ListObject_Deselected()
Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
Me.Application.Worksheets(1)
Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
Globals.Factory.GetVstoObject(NativeWorksheet)
DeselectedList = vstoWorksheet.Controls.AddListObject( _
vstoWorksheet.Range("A1", "C4"), "DeselectedList")
End Sub
Sub List1_Deselected(ByVal Target As _
Microsoft.Office.Interop.Excel.Range) Handles DeselectedList.Deselected
System.Windows.Forms.MessageBox.Show( _
"The list object is no longer selected.")
End Sub
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.");
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。