OriginalDataRestoredEventHandler Delegate (2007 System)

Represents a method that handles the OriginalDataRestored event.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)


Public Delegate Sub OriginalDataRestoredEventHandler ( _
    sender As Object, _
    e As OriginalDataRestoredEventArgs _
Dim instance As New OriginalDataRestoredEventHandler(AddressOf HandlerMethod)
public delegate void OriginalDataRestoredEventHandler(
    Object sender,
    OriginalDataRestoredEventArgs e
public delegate void OriginalDataRestoredEventHandler(
    Object^ sender, 
    OriginalDataRestoredEventArgs^ e
JScript does not support delegates.



When you create an OriginalDataRestoredEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, until you remove the delegate. For more information about delegates, see Events and Delegates.


The following code example creates a DataTable and a ListObject, and binds the ListObject to the DataTable. It then creates an OriginalDataRestored event handler. To test the event, right-click a column letter above the ListObject on sheet 1 and then click Delete in the shortcut menu. The event handler replaces the column and column header data and displays a message indicating what kind of data was restored and the reason that the original data was restored.

This example is for a document-level customization.

WithEvents OriginalDataRestoredList As _
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(New DataColumn("FirstName"))

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

    ' 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(new DataColumn("FirstName"));

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

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

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

    // Create the event handler.
    list1.OriginalDataRestored += new 

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

See Also


Microsoft.Office.Tools.Excel Namespace