DataViewRowState Enumeração

Definição

Descreve a versão dos dados em um DataRow.Describes the version of data in a DataRow.

Esta enumeração tem um atributo FlagsAttribute que permite uma combinação bit a bit dos seus valores membros.

public enum class DataViewRowState
[System.Flags]
public enum DataViewRowState
type DataViewRowState = 
Public Enum DataViewRowState
Herança
DataViewRowState
Atributos

Campos

Added 4

Uma nova linha.A new row.

CurrentRows 22

Linhas atuais, incluindo inalteradas, novas e modificadas.Current rows including unchanged, new, and modified rows. Por padrão, DataViewRowState é definido como CurrentRows.By default, DataViewRowState is set to CurrentRows.

Deleted 8

Uma linha excluída.A deleted row.

ModifiedCurrent 16

A versão atual dos dados originais que foram modificados (consulte ModifiedOriginal).A current version of original data that has been modified (see ModifiedOriginal).

ModifiedOriginal 32

A versão original dos dados que foram modificados.The original version of the data that was modified. (Embora os dados já tenham sido modificados, eles estão disponíveis como ModifiedCurrent).(Although the data has since been modified, it is available as ModifiedCurrent).

None 0

nenhuma.None.

OriginalRows 42

Linhas originais, incluindo linhas inalteradas e excluídas.Original rows including unchanged and deleted rows.

Unchanged 2

Uma linha inalterada.An unchanged row.

Exemplos

No exemplo DataTable a seguir, é criado com uma única coluna.In the following example DataTable is created with a single column. Os dados são alterados e o RowStateFilter DataView de é definido para exibir conjuntos de linhas diferentes, dependendo do 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

Comentários

Os DataViewRowState valores são usados para recuperar uma versão específica de dados de um DataRowou para determinar quais versões existem.The DataViewRowState values are used either to retrieve a particular version of data from a DataRow, or to determine what versions exist.

Defina a RowStateFilter propriedade DataView de para especificar qual versão ou versões de dados você deseja exibir.Set the RowStateFilter property of the DataView to specify which version or versions of data you want to view.

Você pode usar o operador booliano ou com os valores para obter mais de uma versão.You can use the Boolean operator Or with the values to get more than one version.

Os DataTable usos DataViewRowState noSelect método.The DataTable uses DataViewRowState in the Select method.

Aplica-se a

Veja também