ListObject.SelectedIndexChanged 事件
在 SelectedIndex 屬性變更時發生。
命名空間: Microsoft.Office.Tools.Excel
組件: Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)
語法
'宣告
Event SelectedIndexChanged As EventHandler
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 NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
Me.Application.Worksheets(1)
Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
Globals.Factory.GetVstoObject(NativeWorksheet)
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 =
Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]);
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.");
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。