DataViewRowState 枚举

定义

描述 DataRow 中的数据版本。Describes the version of data in a DataRow.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class DataViewRowState
[System.Flags]
public enum DataViewRowState
type DataViewRowState = 
Public Enum DataViewRowState
继承
DataViewRowState
属性

字段

Added 4

新行。A new row.

CurrentRows 22

当前行包括未更改的行、新行和已修改的行。Current rows including unchanged, new, and modified rows. 默认情况下,DataViewRowState 设置为 CurrentRows。By default, DataViewRowState is set to CurrentRows.

Deleted 8

已删除的行。A deleted row.

ModifiedCurrent 16

已修改的原始数据的当前版本(请参阅 ModifiedOriginal)。A current version of original data that has been modified (see ModifiedOriginal).

ModifiedOriginal 32

已修改数据的原始版本。The original version of the data that was modified. (尽管已修改此数据,它仍作为 ModifiedCurrent 可用)。(Although the data has since been modified, it is available as ModifiedCurrent).

None 0

无。None.

OriginalRows 42

原始行包括未更改的行和已删除的行。Original rows including unchanged and deleted rows.

Unchanged 2

未更改的行。An unchanged row.

示例

在下面的示例DataTable中, 创建了一个单独的列。In the following example DataTable is created with a single column. 更改数据, 并RowStateFilter DataView将设置为显示不同的DataViewRowState行集, 具体取决于。The data is changed, and the RowStateFilter of the DataView is set to display different row sets, depending on the DataViewRowState.

static private void DemonstrateRowState()
{
    // Create a DataTable with one column.
    DataTable dataTable = new DataTable("dataTable");
    DataColumn dataColumn = new DataColumn("dataColumn");
    dataTable.Columns.Add(dataColumn);

    // Add ten rows.
    DataRow dataRow;
    for (int i = 0; i < 10; i++)
    {
        dataRow = dataTable.NewRow();
        dataRow["dataColumn"] = "item " + i;
        dataTable.Rows.Add(dataRow);
    }
    dataTable.AcceptChanges();

    // Create a DataView with the table.
    DataView dataView = new DataView(dataTable);

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

    // Add one row:
    dataRow = dataTable.NewRow();
    dataRow["dataColumn"] = "World";
    dataTable.Rows.Add(dataRow);

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

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

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

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

    // Set the RowStateFilter to display only Added and modified rows.
    dataView.RowStateFilter = DataViewRowState.Deleted;
    PrintView(dataView, "Deleted");

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

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

    // Set filter to display only original rows.
    dataView.RowStateFilter = DataViewRowState.OriginalRows;
    PrintView(dataView, "OriginalRows");
}


static private void PrintView(DataView dataView, string label)
{
    Console.WriteLine("\n" + label);
    for (int i = 0; i < dataView.Count; i++)
    {
        Console.WriteLine(dataView[i]["dataColumn"]);
    }
}
Private Sub DemonstrateRowState()
    Dim i As Integer

    ' Create a DataTable with one column.
    Dim dataTable As New DataTable("dataTable")
    Dim dataColumn As New DataColumn("dataColumn")
    dataTable.Columns.Add(dataColumn)

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

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

    ' Change one row's value:
    dataTable.Rows(1)("dataColumn") = "Hello"

    ' Add one row:
    dataRow = dataTable.NewRow()
    dataRow("dataColumn") = "World"
    dataTable.Rows.Add(dataRow)

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

    ' Print those rows. Output = "Hello" "World";
    PrintView(dataView, "ModifiedCurrent and Added")

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

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

    ' Set the RowStateFilter to display only Added and modified rows.
    dataView.RowStateFilter = DataViewRowState.Deleted
    PrintView(dataView, "Deleted")

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

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

    ' Set filter to display only original rows.
    dataView.RowStateFilter = DataViewRowState.OriginalRows
    PrintView(dataView, "OriginalRows")
End Sub

Private Sub PrintView(ByVal dataView As DataView, ByVal label As String)
    Console.WriteLine(ControlChars.Cr + label)
    Dim i As Integer
    For i = 0 To dataView.Count - 1
        Console.WriteLine(dataView(i)("dataColumn"))
    Next i
End Sub

注解

这些DataViewRowState值可用于DataRow从中检索特定版本的数据, 或用于确定存在的版本。The DataViewRowState values are used either to retrieve a particular version of data from a DataRow, or to determine what versions exist.

设置的RowStateFilter DataView属性, 以指定要查看的数据的版本。Set the RowStateFilter property of the DataView to specify which version or versions of data you want to view.

您可以使用布尔运算符或值来获取多个版本。You can use the Boolean operator Or with the values to get more than one version.

方法中DataViewRowState DataTable 的使用SelectThe DataTable uses DataViewRowState in the Select method.

适用于

另请参阅