DataRowView 類別

定義

表示 DataRow 的自訂檢視。

public ref class DataRowView : System::ComponentModel::ICustomTypeDescriptor, System::ComponentModel::IDataErrorInfo, System::ComponentModel::IEditableObject, System::ComponentModel::INotifyPropertyChanged
public ref class DataRowView : System::ComponentModel::ICustomTypeDescriptor, System::ComponentModel::IDataErrorInfo, System::ComponentModel::IEditableObject
public class DataRowView : System.ComponentModel.ICustomTypeDescriptor, System.ComponentModel.IDataErrorInfo, System.ComponentModel.IEditableObject, System.ComponentModel.INotifyPropertyChanged
public class DataRowView : System.ComponentModel.ICustomTypeDescriptor, System.ComponentModel.IDataErrorInfo, System.ComponentModel.IEditableObject
type DataRowView = class
    interface ICustomTypeDescriptor
    interface IDataErrorInfo
    interface IEditableObject
    interface INotifyPropertyChanged
type DataRowView = class
    interface ICustomTypeDescriptor
    interface IEditableObject
    interface IDataErrorInfo
type DataRowView = class
    interface ICustomTypeDescriptor
    interface IEditableObject
    interface IDataErrorInfo
    interface INotifyPropertyChanged
Public Class DataRowView
Implements ICustomTypeDescriptor, IDataErrorInfo, IEditableObject, INotifyPropertyChanged
Public Class DataRowView
Implements ICustomTypeDescriptor, IDataErrorInfo, IEditableObject
繼承
DataRowView
實作

範例

下列範例會 RowVersion 使用 屬性來判斷 中 DataRowView數據列的狀態。 (如需使用 DataRowView.) 的另一個範例,請參閱RowFilter

private static void DemonstrateRowVersion()
{
    // Create a DataTable with one column.
    DataTable table = new DataTable("Table");
    DataColumn column = new DataColumn("Column");
    table.Columns.Add(column);

    // Add ten rows.
    DataRow row;
    for (int i = 0; i < 10; i++)
    {
        row = table.NewRow();
        row["Column"] = "item " + i;
        table.Rows.Add(row);
    }

    table.AcceptChanges();
    // Create a DataView with the table.
    DataView view = new DataView(table);

    // Change one row's value:
    table.Rows[1]["Column"] = "Hello";

    // Add one row:
    row = table.NewRow();
    row["Column"] = "World";
    table.Rows.Add(row);

    // Set the RowStateFilter to display only added
    // and modified rows.
    view.RowStateFilter = DataViewRowState.Added |
        DataViewRowState.ModifiedCurrent;

    // Print those rows. Output includes "Hello" and "World".
    PrintView(view, "ModifiedCurrent and Added");

    // Set filter to display only originals of modified rows.
    view.RowStateFilter = DataViewRowState.ModifiedOriginal;
    PrintView(view, "ModifiedOriginal");

    // Delete three rows.
    table.Rows[1].Delete();
    table.Rows[2].Delete();
    table.Rows[3].Delete();

    // Set the RowStateFilter to display only deleted rows.
    view.RowStateFilter = DataViewRowState.Deleted;
    PrintView(view, "Deleted");

    // Set filter to display only current rows.
    view.RowStateFilter = DataViewRowState.CurrentRows;
    PrintView(view, "Current");

    // Set filter to display only unchanged rows.
    view.RowStateFilter = DataViewRowState.Unchanged;
    PrintView(view, "Unchanged");

    // Set filter to display only original rows.
    // Current values of unmodified rows are also returned.
    view.RowStateFilter = DataViewRowState.OriginalRows;
    PrintView(view, "OriginalRows");
}

private static void PrintView(DataView view, string label)
{
    Console.WriteLine("\n" + label);
    for (int i = 0; i < view.Count; i++)
    {
        Console.WriteLine(view[i]["Column"]);
        Console.WriteLine("DataViewRow.RowVersion: {0}",
            view[i].RowVersion);
    }
}
Private Sub DemonstrateRowVersion()
    Dim i As Integer
    ' Create a DataTable with one column.
    Dim table As New DataTable("Table")
    Dim column As New DataColumn("Column")
    table.Columns.Add(column)

    ' Add ten rows.
    Dim row As DataRow
    For i = 0 To 9
        row = table.NewRow()
        row("Column") = "item " + i.ToString()
        table.Rows.Add(row)
    Next i
    table.AcceptChanges()

    ' Create a DataView with the table.
    Dim view As New DataView(table)

    ' Change one row's value:
    table.Rows(1)("Column") = "Hello"

    ' Add one row:
    row = table.NewRow()
    row("Column") = "World"
    table.Rows.Add(row)

    ' Set the RowStateFilter to display only added and modified rows.
    view.RowStateFilter = _
       DataViewRowState.Added Or DataViewRowState.ModifiedCurrent

    ' Print those rows. Output includes "Hello" and "World".
    PrintView(view, "ModifiedCurrent and Added")

    ' Set filter to display only originals of modified rows.
    view.RowStateFilter = DataViewRowState.ModifiedOriginal
    PrintView(view, "ModifiedOriginal")

    ' Delete three rows.
    table.Rows(1).Delete()
    table.Rows(2).Delete()
    table.Rows(3).Delete()

    ' Set the RowStateFilter to display only deleted rows.
    view.RowStateFilter = DataViewRowState.Deleted
    PrintView(view, "Deleted")

    ' Set filter to display only current rows.
    view.RowStateFilter = DataViewRowState.CurrentRows
    PrintView(view, "Current")

    ' Set filter to display only unchanged rows.
    view.RowStateFilter = DataViewRowState.Unchanged
    PrintView(view, "Unchanged")

    ' Set filter to display only original rows.
    ' Current values of unmodified rows are also returned.
    view.RowStateFilter = DataViewRowState.OriginalRows
    PrintView(view, "OriginalRows")
End Sub

Private Sub PrintView(ByVal view As DataView, ByVal label As String)
    Console.WriteLine(ControlChars.Cr + label)
    Dim i As Integer
    For i = 0 To view.Count - 1
        Console.WriteLine(view(i)("Column"))
        Console.WriteLine("DataRowView.RowVersion: {0}", _
            view(i).RowVersion)
    Next i
End Sub

備註

每當顯示數據時,例如在控件中 DataGrid ,每個數據列只能顯示一個版本。 顯示的資料欄位是 DataRowView

DataRowView可以有四個不同的版本狀態之一:DefaultOriginalCurrentProposed

叫用 BeginEditDataRow之後,任何編輯的值都會 Proposed 變成 值。 CancelEdit在叫用 或 EndEdit 之前,數據列具有 OriginalProposed 版本。 如果 CancelEdit 叫用 ,則會捨棄建議的版本,且值會還原為 Original。 如果 EndEdit 叫用 , DataRowView 則不再有 Proposed 版本;相反地,建議的值會變成目前的值。 預設值僅適用於已定義預設值的數據列。

屬性

DataView

取得這個資料列所屬的 DataView

IsEdit

指示資料列是否處於編輯模式。

IsNew

指示 DataRowView 是否為新的。

Item[Int32]

取得或設定指定資料行中的值。

Item[String]

取得或設定指定資料行中的值。

Row

取得正在檢視的 DataRow

RowVersion

取得 DataRow 的目前版本描述。

方法

BeginEdit()

開始編輯程序。

CancelEdit()

取消編輯程序。

CreateChildView(DataRelation)

使用指定的子 DataView,傳回子系 DataTableDataRelation

CreateChildView(DataRelation, Boolean)

使用指定的 DataRelation 和父系,傳回子系 DataTableDataView

CreateChildView(String)

使用指定的子 DataView 名稱,傳回子系 DataTableDataRelation

CreateChildView(String, Boolean)

使用指定的 DataView 名稱和父代,傳回子系 DataTableDataRelation

Delete()

刪除資料列。

EndEdit()

認可對基礎 DataRow 的變更,並結束以 BeginEdit() 開始的編輯階段作業。 使用CancelEdit()可放棄對DataRow所做的變更。

Equals(Object)

取得值,指出目前的 DataRowView 是否與指定的物件相同。

GetHashCode()

傳回 DataRow 物件的雜湊程式碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

事件

PropertyChanged

DataRowView 屬性變更時所引發的事件。

明確介面實作

ICustomTypeDescriptor.GetAttributes()

傳回元件之這個執行個體的自訂屬性集合。

ICustomTypeDescriptor.GetClassName()

傳回這個元件執行個體的類別名稱。

ICustomTypeDescriptor.GetComponentName()

傳回這個元件執行個體的名稱。

ICustomTypeDescriptor.GetConverter()

傳回這個元件執行個體的類型轉換子。

ICustomTypeDescriptor.GetDefaultEvent()

傳回這個元件執行個體的預設事件。

ICustomTypeDescriptor.GetDefaultProperty()

傳回這個元件執行個體的屬性。

ICustomTypeDescriptor.GetEditor(Type)

傳回元件的這個執行個體之指定類型編輯器。

ICustomTypeDescriptor.GetEvents()

傳回這個元件執行個體的事件。

ICustomTypeDescriptor.GetEvents(Attribute[])

傳回這個含指定屬性之元件執行個體的事件。

ICustomTypeDescriptor.GetProperties()

傳回元件之這個執行個體的屬性。

ICustomTypeDescriptor.GetProperties(Attribute[])

傳回這個含指定屬性之元件執行個體的屬性。

ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor)

傳回物件,包含指定的屬性描述項所描述的屬性。

IDataErrorInfo.Error

取得說明物件驗證錯誤的訊息。

IDataErrorInfo.Item[String]

使用指定的名稱取得屬性的錯誤訊息。

適用於

執行緒安全性

此類型適用於多線程讀取作業。 您必須同步處理任何寫入作業。

另請參閱