OriginalDataRestoredEventArgs 介面
提供 OriginalDataRestored 事件的資料。
命名空間: Microsoft.Office.Tools.Excel
組件: Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)
語法
'宣告
<GuidAttribute("bf384426-1805-4e64-9d3e-79ec84d8bbbd")> _
Public Interface OriginalDataRestoredEventArgs
[GuidAttribute("bf384426-1805-4e64-9d3e-79ec84d8bbbd")]
public interface OriginalDataRestoredEventArgs
OriginalDataRestoredEventArgs 型別會公開下列成員。
屬性
名稱 | 說明 | |
---|---|---|
ChangeReason | 取得表示還原原始資料理由的值。 | |
ChangeType | 取得值,表示 ListObject 控制項所執行的某種還原。 |
回頁首
備註
當 ListObject 控制項還原為其原始狀態時,會引發 OriginalDataRestored 事件。 ChangeType 引數提供 ListObject 控制項所執行之某種還原的資訊,而 ChangeReason 提供有關執行此還原之理由的資訊。
範例
下列程式碼範例會建立 DataTable 和 ListObject,並將 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() + ".");
}