共用方式為


OriginalDataRestoredEventHandler 委派

表示處理 OriginalDataRestored 事件的方法。

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

語法

'宣告
Public Delegate Sub OriginalDataRestoredEventHandler ( _
    sender As Object, _
    e As OriginalDataRestoredEventArgs _
)
public delegate void OriginalDataRestoredEventHandler(
    Object sender,
    OriginalDataRestoredEventArgs e
)

參數

備註

在建立 OriginalDataRestoredEventHandler 委派 (Delegate) 時,你要識別處理事件的方法。 若要讓此事件與您的事件處理常式產生關聯,請將委派的執行個體加入至此事件。 在您移除該委派之前,每當事件發生,就會呼叫事件處理常式。

範例

下列程式碼範例會建立 DataTableListObject,並將 ListObject 繫結至 DataTable。 接著會建立 OriginalDataRestored 事件處理常式。 若要測試事件,請在工作表 1 的 ListObject 上方的資料行字母上按一下滑鼠右鍵,然後在捷徑功能表中按一下 [刪除]。 事件處理常式會取代資料行和資料行行首資料,並顯示一則訊息,指出還原了何種資料,以及為什麼要還原原始資料。

這是示範文件層級自訂的範例。

    WithEvents OriginalDataRestoredList As _
        Microsoft.Office.Tools.Excel.ListObject
    Private Sub ListObject_OriginalDataRestored()
        ' Create a new DataSet and DataTable.
        Dim ds As New DataSet()
        Dim dt As DataTable = ds.Tables.Add("Customers")
        Dim lastName As New DataColumn("LastName")
        dt.Columns.Add(lastName)
        dt.Columns.Add(New DataColumn("FirstName"))

        ' Add two new rows to the DataTable.
        Dim dr1 As DataRow = dt.NewRow()
        dr1("LastName") = "Chan"
        dr1("FirstName") = "Gareth"
        dt.Rows.Add(dr1)
        Dim dr2 As DataRow = dt.NewRow()
        dr2("LastName") = "Nitsche"
        dr2("FirstName") = "Sonja"
        dt.Rows.Add(dr2)

        ' Create a list object.
        OriginalDataRestoredList = Me.Controls.AddListObject( _
            Me.Range("A1"), "OriginalDataRestoredList")

        ' Bind the list object to the DataTable.
        OriginalDataRestoredList.AutoSetDataBoundColumnHeaders = True
        OriginalDataRestoredList.SetDataBinding(ds, "Customers", _
            "LastName", "FirstName")
    End Sub

    Private Sub List1_OriginalDataRestored(ByVal sender As Object, _
        ByVal e As Microsoft.Office.Tools.Excel.OriginalDataRestoredEventArgs) _
        Handles OriginalDataRestoredList.OriginalDataRestored
        MessageBox.Show("This data is bound to a data source and " & _
        "will be restored. This change is: " & e.ChangeType.ToString() & _
        ". The reason is: " & e.ChangeReason.ToString() + ".")
    End Sub

private void ListObject_OriginalDataRestored()
{
    // Create a new DataSet and DataTable.
    DataSet ds = new DataSet();
    DataTable dt = ds.Tables.Add("Customers");
    DataColumn lastName = new DataColumn("LastName");
    dt.Columns.Add(lastName);
    dt.Columns.Add(new DataColumn("FirstName"));

    // Add two new rows to the DataTable.
    DataRow dr1 = dt.NewRow();
    dr1["LastName"] = "Chan";
    dr1["FirstName"] = "Gareth";
    dt.Rows.Add(dr1);
    DataRow dr2 = dt.NewRow();
    dr2["LastName"] = "Nitsche";
    dr2["FirstName"] = "Sonja";
    dt.Rows.Add(dr2);

    // Create a list object.
    Microsoft.Office.Tools.Excel.ListObject list1 = 
        this.Controls.AddListObject(
        this.Range["A1"], "list1");

    // Bind the list object to the DataTable.
    list1.AutoSetDataBoundColumnHeaders = true;
    list1.SetDataBinding(ds, "Customers", "LastName",
        "FirstName");

    // Create the event handler.
    list1.OriginalDataRestored += new 
        Microsoft.Office.Tools.Excel.
        OriginalDataRestoredEventHandler(list1_OriginalDataRestored);
}

void list1_OriginalDataRestored(object sender, 
    Microsoft.Office.Tools.Excel.OriginalDataRestoredEventArgs e)
{
    MessageBox.Show("This data is bound to a data source and " +
    "will be restored. This change is: " + e.ChangeType.ToString() +
    ". The reason is: " + e.ChangeReason.ToString() + ".");
}

請參閱

參考

Microsoft.Office.Tools.Excel 命名空間