ListObject.SelectedIndexChanged 事件 (2007 系統)
更新: 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 功能變更。 |