DataView.RowStateFilter DataView.RowStateFilter DataView.RowStateFilter DataView.RowStateFilter Property

정의

DataView에 사용되는 행 상태 필터를 가져오거나 설정합니다.Gets or sets the row state filter used in the DataView.

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

속성 값

예제

다음 예제에서는 DataTable 단일 열 및 다음 변경 집합과 데이터를 RowStateFilterDataView 에 따라 다른 행 집합을 표시 하는 DataViewRowState.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.

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합니다.Only rows that have been deleted by using the Delete method will have their RowStateFilter value set to Deleted. 사용 하 여 추가 된 행을 AddNew 메서드는 마찬가지로 속성이로 설정 해야 Added합니다.Those rows added using the AddNew method will similarly have the property set to Added.

참고

사용 하는 Remove 메서드를 DataRowCollection 클래스는 행으로 표시 되어야 되지는지 않습니다 Deleted합니다.Using the Remove method of the DataRowCollection class does not mean that a row will be marked as Deleted. 사용 된 Delete 메서드 대신 이러한 행 되도록에서 볼 수 있습니다는 DataView합니다.Use the Delete method instead to make sure that such rows can be viewed in the DataView.

새 행도 표시 됩니다 때 합니다 RowStateFilter 로 설정 된 ModifiedCurrent 또는 CurrentRows합니다.New rows will also be visible when the RowStateFilter is set to ModifiedCurrent or CurrentRows.

삭제 된 행도 표시 됩니다 때 합니다 RowStateFilter 로 설정 된 ModifiedOriginalOriginalRows합니다.Deleted rows will also be visible when the RowStateFilter is set to ModifiedOriginal and OriginalRows.

적용 대상

추가 정보