Export (0) Print
Expand All
Expand Minimize
3 out of 4 rated this helpful - Rate this topic

DataViewRowState Enumeration

Describes the version of data in a DataRow.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

[Visual Basic]
<Flags>
<Serializable>
Public Enum DataViewRowState
[C#]
[Flags]
[Serializable]
public enum DataViewRowState
[C++]
[Flags]
[Serializable]
__value public enum DataViewRowState
[JScript]
public
   Flags
 Serializable
enum DataViewRowState

Remarks

The DataViewRowState values are used either to retrieve a particular version of data from a DataRow, or to determine what versions exist.

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.

The DataTable uses DataViewRowState in the Select method.

Members

Member name Description Value
Added

Supported by the .NET Compact Framework.

A new row. 4
CurrentRows

Supported by the .NET Compact Framework.

Current rows including unchanged, new, and modified rows. 22
Deleted

Supported by the .NET Compact Framework.

A deleted row. 8
ModifiedCurrent

Supported by the .NET Compact Framework.

A current version, which is a modified version of original data (see ModifiedOriginal). 16
ModifiedOriginal

Supported by the .NET Compact Framework.

The original version (although it has since been modified and is available as ModifiedCurrent). 32
None

Supported by the .NET Compact Framework.

None. 0
OriginalRows

Supported by the .NET Compact Framework.

Original rows including unchanged and deleted rows. 42
Unchanged

Supported by the .NET Compact Framework.

An unchanged row. 2

Example

[Visual Basic, C#, C++] In the following example DataTable is created with a single column. The data and is changed, and the RowStateFilter of the DataView is set to display different row sets, depending on the DataViewRowState.

[Visual Basic] 
Private Sub DemonstrateRowState()
    Dim i As Integer
    ' Create a DataTable with one column.
    Dim myTable As New DataTable("myTable")
    Dim myColumn As New DataColumn("myColumn")
    myTable.Columns.Add(myColumn)
    ' Add ten rows.
    Dim myRow As DataRow
    For i = 0 To 9
        myRow = myTable.NewRow()
        myRow("myColumn") = "item " + i.ToString()
        myTable.Rows.Add(myRow)
    Next i
    myTable.AcceptChanges()
    ' Create a DataView with the table.
    Dim myView As New DataView(myTable)
    ' Change one row's value:
    myTable.Rows(1)("myColumn") = "Hello"
    ' Add one row:
    myRow = myTable.NewRow()
    myRow("myColumn") = "World"
    myTable.Rows.Add(myRow)
    ' Set the RowStateFilter to display only Added and modified rows.
    myView.RowStateFilter = _
       DataViewRowState.Added Or DataViewRowState.ModifiedCurrent
    ' Print those rows. Output = "Hello" "World";
    PrintView(myView, "ModifiedCurrent and Added")
    ' Set filter to display on originals of modified rows.
    myView.RowStateFilter = DataViewRowState.ModifiedOriginal
    PrintView(myView, "ModifiedOriginal")
    ' Delete three rows.
    myTable.Rows(1).Delete()
    myTable.Rows(2).Delete()
    myTable.Rows(3).Delete()
    ' Set the RowStateFilter to display only Added and modified rows.
    myView.RowStateFilter = DataViewRowState.Deleted
    PrintView(myView, "Deleted")
    'Set filter to display only current.
    myView.RowStateFilter = DataViewRowState.CurrentRows
    PrintView(myView, "Current")
    ' Set filter to display only unchanged rows.
    myView.RowStateFilter = DataViewRowState.Unchanged
    PrintView(myView, "Unchanged")
    ' Set filter to display only original rows.
    myView.RowStateFilter = DataViewRowState.OriginalRows
    PrintView(myView, "OriginalRows")
End Sub
   
Private Sub PrintView(dv As DataView, label As String)
    Console.WriteLine(ControlChars.Cr + label)
    Dim i As Integer
    For i = 0 To dv.Count - 1
        Console.WriteLine(dv(i)("myColumn"))
    Next i
End Sub

[C#] 
private void DemonstrateRowState(){
   int i;
   // Create a DataTable with one column.
   DataTable myTable = new DataTable("myTable");
   DataColumn myColumn = new DataColumn("myColumn");
   myTable.Columns.Add(myColumn);
   // Add ten rows.
   DataRow myRow;
   for(i = 0;i < 10 ;i++) {
      myRow = myTable.NewRow();
      myRow["myColumn"] = "item " + i;
      myTable.Rows.Add(myRow);
   }
   myTable.AcceptChanges();
   // Create a DataView with the table.
   DataView myView = new DataView(myTable);
   // Change one row's value:
   myTable.Rows[1]["myColumn"] = "Hello";
   // Add one row:
   myRow = myTable.NewRow();
   myRow["myColumn"] = "World";
   myTable.Rows.Add(myRow);
   // Set the RowStateFilter to display only Added and modified rows.
   myView.RowStateFilter=DataViewRowState.Added | DataViewRowState.ModifiedCurrent;
   // Print those rows. Output = "Hello" "World";
   PrintView(myView, "ModifiedCurrent and Added");
   // Set filter to display on originals of modified rows.
   myView.RowStateFilter=DataViewRowState.ModifiedOriginal;
   PrintView(myView,"ModifiedOriginal");
   // Delete three rows.
   myTable.Rows[1].Delete();
   myTable.Rows[2].Delete();
   myTable.Rows[3].Delete();
   // Set the RowStateFilter to display only Added and modified rows.
   myView.RowStateFilter=DataViewRowState.Deleted;
   PrintView(myView,"Deleted");
   //Set filter to display only current.
   myView.RowStateFilter=DataViewRowState.CurrentRows;
   PrintView(myView,"Current");
   // Set filter to display only unchanged rows.
   myView.RowStateFilter=DataViewRowState.Unchanged; 
   PrintView(myView,"Unchanged");
   // Set filter to display only original rows.
   myView.RowStateFilter=DataViewRowState.OriginalRows ; 
   PrintView(myView,"OriginalRows");
}


private void PrintView(DataView dv,string label){
   Console.WriteLine("\n" + label);
   for(int i = 0;i < dv.Count ;i++) {
      Console.WriteLine(dv[i]["myColumn"]);
   }
}

[C++] 
private:
 void DemonstrateRowState(){
    int i;
    // Create a DataTable with one column.
    DataTable* myTable = new DataTable(S"myTable");
    DataColumn* myColumn = new DataColumn(S"myColumn");
    myTable->Columns->Add(myColumn);
    // Add ten rows.
    DataRow* myRow;
    for(i = 0;i < 10 ;i++) {
       myRow = myTable->NewRow();
       myRow->Item[S"myColumn"] = String::Format( S"item {0}", __box(i));
       myTable->Rows->Add(myRow);
    }
    myTable->AcceptChanges();
    // Create a DataView with the table.
    DataView* myView = new DataView(myTable);
    // Change one row's value:
    myTable->Rows->Item[1]->Item[S"myColumn"] = S"Hello";
    // Add one row:
    myRow = myTable->NewRow();
    myRow->Item[S"myColumn"] = S"World";
    myTable->Rows->Add(myRow);
    // Set the RowStateFilter to display only Added and modified rows.
    myView->RowStateFilter= static_cast<DataViewRowState>
       (DataViewRowState::Added | DataViewRowState::ModifiedCurrent);
    // Print those rows. Output = "Hello" "World";
    PrintView(myView, S"ModifiedCurrent and Added");
    // Set filter to display on originals of modified rows.
    myView->RowStateFilter=DataViewRowState::ModifiedOriginal;
    PrintView(myView,S"ModifiedOriginal");
    // Delete three rows.
    myTable->Rows->Item[1]->Delete();
    myTable->Rows->Item[2]->Delete();
    myTable->Rows->Item[3]->Delete();
    // Set the RowStateFilter to display only Added and modified rows.
    myView->RowStateFilter=DataViewRowState::Deleted;
    PrintView(myView,S"Deleted");
    //Set filter to display only current.
    myView->RowStateFilter=DataViewRowState::CurrentRows;
    PrintView(myView,S"Current");
    // Set filter to display only unchanged rows.
    myView->RowStateFilter=DataViewRowState::Unchanged; 
    PrintView(myView,S"Unchanged");
    // Set filter to display only original rows.
    myView->RowStateFilter=DataViewRowState::OriginalRows ; 
    PrintView(myView,S"OriginalRows");
 }
 
 void PrintView(DataView* dv,String* label){
    Console::WriteLine(S"\n{0}", label);
    for(int i = 0;i < dv->Count ;i++) {
       Console::WriteLine(dv->Item[i]->Item[S"myColumn"]);
    }
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Data

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Data (in System.Data.dll)

See Also

System.Data Namespace | DataRow | DataView | DataView | Select

Show:
© 2014 Microsoft. All rights reserved.