Export (0) Print
Expand All
Expand Minimize
0 out of 1 rated this helpful - Rate this topic

ChangeType Enumeration

Provides information about how a ListObject control restored data that was changed by a user.

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)

public enum ChangeType
 Member nameDescription
ColumnAddedA column was added to the ListObject control. 
ColumnHeaderRestoredThe text for the column header was restored to its original value. 
ColumnRemovedA column was removed from the ListObject control. 
RangeValueRestoredThe values in a range were restored to the values in the data source. 
RowAddedA row was added to the ListObject control. 
RowRemovedA row was removed from the ListObject control. 

When the ListObject control is bound to data and the user performs an operation that is not allowed, the ListObject control restores itself to its previous state and raises the OriginalDataRestored event. The ChangeType enumeration provides information about the kind of restoration that 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.

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", missing], "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() + ".");
}

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.