다음을 통해 공유


DataView.RowStateFilter 속성

정의

DataView에 사용되는 행 상태 필터를 가져오거나 설정합니다.

public:
 property System::Data::DataViewRowState RowStateFilter { System::Data::DataViewRowState get(); void set(System::Data::DataViewRowState value); };
public System.Data.DataViewRowState RowStateFilter { get; set; }
[System.Data.DataSysDescription("DataViewRowStateFilterDescr")]
public System.Data.DataViewRowState RowStateFilter { get; set; }
member this.RowStateFilter : System.Data.DataViewRowState with get, set
[<System.Data.DataSysDescription("DataViewRowStateFilterDescr")>]
member this.RowStateFilter : System.Data.DataViewRowState with get, set
Public Property RowStateFilter As DataViewRowState

속성 값

DataViewRowState 값 중 하나입니다.

특성

예제

다음 예제에서는 단일 열로 를 DataTable 만든 다음 데이터를 변경하고 의 DataView 를 설정 RowStateFilter 하여 에 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

설명

메서드를 사용하여 Delete 삭제된 행만 해당 RowStateFilter 값이 로 Deleted설정됩니다. 메서드를 사용하여 추가된 AddNew 행도 마찬가지로 속성이 로 설정 Added됩니다.

참고

Remove 클래스의 메서드를 DataRowCollection 사용한다고 해서 행이 로 Deleted표시되는 것은 아닙니다. 메서드를 Delete 대신 사용하여 에서 이러한 행을 볼 DataView수 있는지 확인합니다.

가 또는 CurrentRows로 설정된 ModifiedCurrent 경우에도 RowStateFilter 새 행이 표시됩니다.

가 및 OriginalRows로 설정된 ModifiedOriginal 경우에도 RowStateFilter 삭제된 행이 표시됩니다.

적용 대상

추가 정보