本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

ListObject.SelectedIndexChanged 事件

 

發生於 SelectedIndex 屬性的值變更時。

命名空間:   Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (於 Microsoft.Office.Tools.Excel.dll)

event EventHandler SelectedIndexChanged

This event is not raised if the header, Insert row or Total row is selected.

This event is raised if the P:Microsoft.Office.Tools.Excel.ListObject.SelectedIndex property is changed by either a programmatic modification or user interaction.

The following code example creates a T:Microsoft.Office.Tools.Excel.ListObject on the current worksheet. It uses the P:Microsoft.Office.Tools.Excel.ListObject.SelectedIndex and P:Microsoft.Office.Tools.Excel.ListObject.AutoSelectRows properties to select the second row and to specify that the entire row is selected when the user clicks a row. The code example also creates an event handler for the E:Microsoft.Office.Tools.Excel.ListObject.SelectedIndexChanged event that displays a message box whenever a new row is selected.

This version is for a document-level customization.

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.");
}

This version is for an application-level add-in.

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.");
}
回到頁首
顯示: