ListObject.SelectedIndexChanged 事件 (2007 system)
更新: 2008 年 7 月
当 SelectedIndex 属性的值更改时发生。
命名空间: Microsoft.Office.Tools.Excel
程序集: Microsoft.Office.Tools.Excel.v9.0(在 Microsoft.Office.Tools.Excel.v9.0.dll 中)
语法
声明
Public Event SelectedIndexChanged As EventHandler
用法
Dim instance As ListObject
Dim handler As EventHandler
AddHandler instance.SelectedIndexChanged, handler
public event EventHandler SelectedIndexChanged
备注
如果选择了标题行、插入行或总计行,将不引发此事件。
如果通过编程修改或用户交互更改 SelectedIndex 属性,则将引发此事件。
示例
下面的代码示例在当前的工作表上创建一个 ListObject。它使用 SelectedIndex 和 AutoSelectRows 属性选择第二行并指定在用户单击某一行时将选择整行。该代码示例还为在选择新行时显示消息框的 SelectedIndexChanged 事件创建事件处理程序。
此版本针对的是文档级自定义项。
WithEvents SelectedIndexList As Microsoft.Office.Tools.Excel.ListObject
Private Sub ListObject_SelectedIndex()
SelectedIndexList = _
Me.Controls.AddListObject(Me.Range("A1", "D4"), _
"SelectedIndexList")
SelectedIndexList.AutoSelectRows = True
SelectedIndexList.SelectedIndex = 2
End Sub
Private Sub List1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As EventArgs) Handles SelectedIndexList.SelectedIndexChanged
MessageBox.Show("Selected index has changed.")
End Sub
private void ListObject_SelectedIndex()
{
Microsoft.Office.Tools.Excel.ListObject list1 =
this.Controls.AddListObject(this.Range["A1", "D4"],
"list1");
list1.AutoSelectRows = true;
list1.SelectedIndex = 2;
list1.SelectedIndexChanged +=
new EventHandler(list1_SelectedIndexChanged);
}
void list1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("Selected index has changed.");
}
此版本针对的是应用程序级外接程序。
WithEvents SelectedIndexList As ListObject
Private Sub ListObject_SelectedIndex()
Dim vstoWorksheet As Worksheet = CType( _
Me.Application.ActiveWorkbook.Worksheets(1), _
Excel.Worksheet).GetVstoObject()
SelectedIndexList = _
vstoWorksheet.Controls.AddListObject( _
vstoWorksheet.Range("A1", "D4"), _
"SelectedIndexList")
SelectedIndexList.AutoSelectRows = True
SelectedIndexList.SelectedIndex = 2
End Sub
Private Sub List1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As EventArgs) Handles SelectedIndexList.SelectedIndexChanged
System.Windows.Forms.MessageBox.Show("Selected index has changed.")
End Sub
private void ListObject_SelectedIndex()
{
Worksheet vstoWorksheet = ((Excel.Worksheet)
this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
ListObject list1 =
vstoWorksheet.Controls.AddListObject(
vstoWorksheet.Range["A1", "D4"],
"list1");
list1.AutoSelectRows = true;
list1.SelectedIndex = 2;
list1.SelectedIndexChanged +=
new EventHandler(list1_SelectedIndexChanged);
}
void list1_SelectedIndexChanged(object sender, EventArgs e)
{
System.Windows.Forms.MessageBox.Show("Selected index has changed.");
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
另请参见
参考
Microsoft.Office.Tools.Excel 命名空间
修订记录
日期 |
修订记录 |
原因 |
---|---|---|
2008 年 7 月 |
添加了一个针对应用程序级外接程序的代码示例版本。 |
SP1 功能更改。 |