DataRow.RejectChanges 메서드

정의

AcceptChanges()를 마지막으로 호출한 이후에 수행된 행의 모든 변경 내용을 취소합니다.Rejects all changes made to the row since AcceptChanges() was last called.

public:
 void RejectChanges();
public void RejectChanges ();
member this.RejectChanges : unit -> unit
Public Sub RejectChanges ()

예외

행이 테이블에 속하지 않는 경우The row does not belong to the table.

예제

다음 예제에서는 간단한 DataTable 10 행과 2 열입니다.The following example creates a simple DataTable with 2 columns and 10 rows. 여러 후 DataRow 항목을 사용 하 여 삭제 합니다 Delete 행 중 하나는 메서드를 호출 하 여 삭제를 취소 RejectChanges합니다.After several DataRow items are deleted with the Delete method, one of the rows is undeleted by invoking RejectChanges.

private void DemonstrateDeleteRow()
{
    // Create a simple DataTable with two columns and ten rows.
    DataTable table = new DataTable("table");
    DataColumn idColumn = new DataColumn("id",
        Type.GetType("System.Int32"));
    idColumn.AutoIncrement=true;
    DataColumn itemColumn = new DataColumn("item", 
        Type.GetType("System.String"));
    table.Columns.Add(idColumn);
    table.Columns.Add(itemColumn);

    // Add ten rows.
    DataRow newRow;
     
    for(int i = 0; i <10; i++)
    {
        newRow = table.NewRow();
        newRow["item"] = "Item " + i;
        table.Rows.Add(newRow);
    }
    table.AcceptChanges();

    DataRowCollection itemColumns = table.Rows;
    itemColumns[0].Delete();
    itemColumns[2].Delete();
    itemColumns[3].Delete();
    itemColumns[5].Delete();
    Console.WriteLine(itemColumns[3].RowState.ToString());

    // Reject changes on one deletion.
    itemColumns[3].RejectChanges();

    // Change the value of the column so it stands out.
    itemColumns[3]["item"] = "Deleted, Undeleted, Edited";

    // Accept changes on others.
    table.AcceptChanges();

    // Print the remaining row values.
    foreach(DataRow row in table.Rows)
    {
        Console.WriteLine(row[0] + "\table" + row[1]);
    }
}
 Private Sub DemonstrateDeleteRow()
     ' Create a simple DataTable with two columns and ten rows.
     Dim table As New DataTable("table")
     Dim idColumn As New DataColumn("id", Type.GetType("System.Int32"))
     idColumn.AutoIncrement = True
     Dim itemColumn As New DataColumn("item", Type.GetType("System.String"))
     table.Columns.Add(idColumn)
     table.Columns.Add(itemColumn)

     ' Add ten rows.
     Dim newRow As DataRow
     
     Dim i As Integer
     For i = 0 To 9
         newRow = table.NewRow()
         newRow("item") = "Item " & i.ToString()
         table.Rows.Add(newRow)
     Next i
     table.AcceptChanges()

     Dim itemColumns As DataRowCollection = table.Rows
     itemColumns(0).Delete()
     itemColumns(2).Delete()
     itemColumns(3).Delete()
     itemColumns(5).Delete()
     Console.WriteLine(itemColumns(3).RowState.ToString())

     ' Reject changes on one deletion.
     itemColumns(3).RejectChanges()

     ' Change the value of the column so it stands out.
     itemColumns(3)("item") = "Deleted, Undeleted, Edited"

     ' Accept changes on others.
     table.AcceptChanges()

     ' Print the remaining row values.
     Dim row As DataRow
     For Each row In  table.Rows
         Console.WriteLine(row(0).ToString() & ControlChars.Tab _
            & row(1).ToString())
     Next row
End Sub

설명

호출 하는 경우는 RejectChanges 메서드는 CancelEdit 암시적으로 메서드는 편집을 취소 합니다.When you call the RejectChanges method, the CancelEdit method is implicitly called to cancel any edits. 하는 경우 RowState 삭제 하거나 수정 하 고, 행의 이전 값으로 되돌아갑니다 및 RowState 변경 됩니다.If RowState is deleted or modified, the row reverts to its previous values, and RowState becomes unchanged. 경우는 RowState 에 추가 된 행이 제거 됩니다.If the RowState is added, the row is removed.

적용 대상

추가 정보