ChangeReason Enumeration


Provides the reason that the original data was restored to a ListObject that is bound to data.

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

public enum ChangeReason

Member nameDescription

When the AutoSetDataBoundColumnHeaders property of the ListObject control is set to true, the ListObject control does not allow the user to change the column headers.


A change to data in the ListObject control could not be committed to the data source that the control is bound to.


The data source that the ListObject control is bound to does not allow adding or removing rows.


The ListObject control does not allow columns to be added or removed after it is bound to data.


The original data was restored because of a reason not specified by any of the other ChangeReason values.


The data source that the ListObject control is bound to is read-only.

When the ListObject is bound to data and the user performs an operation that is not allowed, the ListObject restores itself to its previous state and raises the OriginalDataRestored event. The ChangeReason enumeration provides information about why this restoration occurred.

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.

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"], "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() + ".");
Return to top