ListObject.Selected 事件 (2007 系統)
更新: 2008 年 7 月
當選取 ListObject 控制項時發生。
命名空間: Microsoft.Office.Tools.Excel
組件: Microsoft.Office.Tools.Excel.v9.0 (在 Microsoft.Office.Tools.Excel.v9.0.dll 中)
語法
Public Event Selected As DocEvents_SelectionChangeEventHandler
Dim instance As ListObject
Dim handler As DocEvents_SelectionChangeEventHandler
AddHandler instance.Selected, handler
public 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 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.");
}
使用權限
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.Office.Tools.Excel 命名空間
變更記錄
日期 |
記錄 |
原因 |
---|---|---|
2008 年 7 月 |
加入應用程式層級增益集的程式碼範例版本。 |
SP1 功能變更。 |