共用方式為


ListObjectChangeHandler 委派

表示處理 ListObjectChange 事件的方法。

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

語法

'宣告
Public Delegate Sub ListObjectChangeHandler ( _
    targetRange As Range, _
    changedRanges As ListRanges _
)
public delegate void ListObjectChangeHandler(
    Range targetRange,
    ListRanges changedRanges
)

參數

備註

在建立 ListObjectChangeHandler 委派 (Delegate) 時,您要識別處理事件的方法。 若要讓此事件與您的事件處理常式產生關聯,請將委派的執行個體加入至此事件。 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。 如需委派的詳細資訊,請參閱事件和委派

範例

下列程式碼範例會建立 ListObjectChange 事件處理常式。 若要引發 Change 事件,請將文字加入至 ListObject 中的一個儲存格,然後按 ENTER 鍵。

WithEvents ChangeList As Microsoft.Office.Tools.Excel.ListObject
Private Sub ListObject_Change()
    ChangeList = Me.Controls.AddListObject( _
        Me.Range("A1", "C4"), "ChangeList")
End Sub


Sub List1_Change(ByVal targetRange As _
    Microsoft.Office.Interop.Excel.Range, _
    ByVal changedRanges As Microsoft.Office.Tools.Excel.ListRanges) _
    Handles ChangeList.Change

    Dim cellAddress As String = targetRange.Address( _
        ReferenceStyle:=Excel.XlReferenceStyle.xlA1)

    Select Case changedRanges
        Case Microsoft.Office.Tools.Excel.ListRanges.DataBodyRange
            MsgBox("The cells at range " & cellAddress & _
                " in the data body changed.")
        Case Microsoft.Office.Tools.Excel.ListRanges.HeaderRowRange
            MsgBox("The cells at range " & cellAddress & _
                " in the header row changed.")
        Case Microsoft.Office.Tools.Excel.ListRanges.TotalsRowRange
            MsgBox("The cells at range " & cellAddress & _
                " in the totals row changed.")
        Case Else
            MsgBox("The cells at range " & cellAddress & _
                " changed.")
    End Select
End Sub
private void ListObject_Change()
{
    Microsoft.Office.Tools.Excel.ListObject list1 = 
        this.Controls.AddListObject(
        this.Range["A1", "C4"], "list1");
    list1.Change += new Microsoft.Office.Tools.Excel.
        ListObjectChangeHandler(list1_Change);
}

void list1_Change(Microsoft.Office.Interop.Excel.Range 
    targetRange, Microsoft.Office.Tools.Excel.ListRanges 
    changedRanges)
{
    string cellAddress = targetRange.get_Address(
        Excel.XlReferenceStyle.xlA1 
        );

    switch (changedRanges)
    {
        case Microsoft.Office.Tools.Excel.ListRanges.DataBodyRange:
            MessageBox.Show("The cells at range " + cellAddress +
                " in the data body changed.");
            break;
        case Microsoft.Office.Tools.Excel.ListRanges.HeaderRowRange:
            MessageBox.Show("The cells at range " + cellAddress +
                " in the header row changed.");
            break;
        case Microsoft.Office.Tools.Excel.ListRanges.TotalsRowRange:
            MessageBox.Show("The cells at range " + cellAddress +
                " in the totals row changed.");
            break;
        default:
            MessageBox.Show("The cells at range " + cellAddress +
                " changed.");
            break;
    }
}

請參閱

參考

Microsoft.Office.Tools.Excel 命名空間