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。 (请参阅 RowFilter 使用 DataRowView.) 的另一个示例

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

A DataRowView 可以有四种不同的版本状态之一: DefaultOriginalCurrentProposed

调用 BeginEdit a DataRow后,任何编辑的值都 Proposed 将成为值。 在调用或CancelEditEndEdit调用之前,行具有一个Original和一个Proposed版本。 如果 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]

获取具有给定名称的属性的错误信息。

适用于

线程安全性

此类型对于多线程读取操作是安全的。 必须同步任何写入操作。

另请参阅