ListObject.SelectionChange 事件
在 ListObject 控件内部的所选内容更改时发生。
命名空间: Microsoft.Office.Tools.Excel
程序集: Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)
语法
声明
Event SelectionChange As DocEvents_SelectionChangeEventHandler
event DocEvents_SelectionChangeEventHandler SelectionChange
备注
当 ListObject 中的任何选定范围发生更改时,将引发此事件。
当将焦点从 ListObject 控件内部移到 ListObject 控件外部时,不引发此事件。当将焦点从 ListObject 控件外部移到 ListObject 控件时,将引发此事件。
示例
下面的代码示例创建一个 ListObject,然后为 SelectionChange 事件创建事件处理程序。若要测试此事件处理程序,请在 ListObject 中选择一个单元格,然后在 ListObject 中选择另一个单元格。
此版本针对的是文档级自定义项。
WithEvents SelectionChangeList As Microsoft.Office.Tools.Excel.ListObject
Private Sub ListObject_SelectionChange()
SelectionChangeList = Me.Controls.AddListObject( _
Me.Range("A1", "C4"), "SelectionChangeList")
End Sub
Sub List1_SelectionChange(ByVal Target As _
Microsoft.Office.Interop.Excel.Range) _
Handles SelectionChangeList.SelectionChange
MessageBox.Show("The selection in the list object has changed.")
End Sub
private void ListObject_SelectionChange()
{
Microsoft.Office.Tools.Excel.ListObject list1 =
this.Controls.AddListObject(
this.Range["A1", "C4"], "list1");
list1.SelectionChange += new Microsoft.Office.Interop.
Excel.DocEvents_SelectionChangeEventHandler(
list1_SelectionChange);
}
void list1_SelectionChange(Microsoft.Office.Interop.Excel.Range Target)
{
MessageBox.Show("The selection in the list object has changed.");
}
此版本针对的是应用程序级外接程序。
WithEvents SelectionChangeList As ListObject
Private Sub ListObject_SelectionChange()
Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
Me.Application.Worksheets(1)
Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
Globals.Factory.GetVstoObject(NativeWorksheet)
SelectionChangeList = vstoWorksheet.Controls.AddListObject( _
vstoWorksheet.Range("A1", "C4"), "SelectionChangeList")
End Sub
Sub List1_SelectionChange(ByVal Target As _
Microsoft.Office.Interop.Excel.Range) _
Handles SelectionChangeList.SelectionChange
System.Windows.Forms.MessageBox.Show( _
"The selection in the list object has changed.")
End Sub
private void ListObject_SelectionChange()
{
Worksheet vstoWorksheet =
Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]); ;
ListObject list1 =
vstoWorksheet.Controls.AddListObject(
vstoWorksheet.Range["A1", "C4"], "list1");
list1.SelectionChange += new
Excel.DocEvents_SelectionChangeEventHandler(
list1_SelectionChange);
}
void list1_SelectionChange(Excel.Range Target)
{
System.Windows.Forms.MessageBox.Show("The selection in the list object has changed.");
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。