This documentation is archived and is not being maintained.

DataView.RowStateFilter Property

Gets or sets the row state filter used in the DataView.

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

Public Property RowStateFilter As DataViewRowState
Dim instance As DataView 
Dim value As DataViewRowState 

value = instance.RowStateFilter

instance.RowStateFilter = value

Property Value

Type: System.Data.DataViewRowState
One of the DataViewRowState values.

Only rows that have been deleted by using the Delete method will have their RowStateFilter value set to Deleted. Those rows added using the AddNew method will similarly have the property set to Added.


 Using the Remove method of the DataRowCollection class does not mean that a row will be marked as Deleted. Use the Delete method instead to make sure that such rows can be viewed in the DataView.

New rows will also be visible when the RowStateFilter is set to ModifiedCurrent or CurrentRows.

Deleted rows will also be visible when the RowStateFilter is set to ModifiedOriginal and OriginalRows.

The following example creates a DataTable with a single column, and then changes the data and sets the RowStateFilter of the DataView to display different row sets, depending on the DataViewRowState.

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")

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

    ' 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"

    ' 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.

    ' 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
    Next i
End Sub

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0