DataRow.BeginEdit 메서드

정의

DataRow 개체에 대한 편집 작업을 시작합니다.

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

예외

RowChanging 이벤트 내부에서 메서드를 호출한 경우

삭제된 행에서 메서드를 호출한 경우

예제

이 예제에서는 1개와 5개의 DataColumnDataRow 개체와 를 사용하여 간단한 DataTableUniqueConstraint만듭니다. RowChanged 또한 행의 값이 변경되는 시기를 모니터링하기 위해 이벤트 처리기가 추가됩니다. 기존 행에서 를 호출하면 BeginEdit 제약 조건 및 이벤트가 일시적으로 비활성화되고 원래 값과 제안된 값이 인쇄됩니다. 는 BeginEdit 두 행을 동일한 값으로 설정하기 위해 다시 호출됩니다. 가 호출될 때 EndEditUniqueConstraint 동일한 값에 적용됩니다.

private void DemonstrateRowBeginEdit()
{
    DataTable table = new DataTable("table1");
    DataColumn column = new
        DataColumn("col1",Type.GetType("System.Int32"));
    table.RowChanged+=new
        DataRowChangeEventHandler(Row_Changed);
    table.Columns.Add(column);

    // Add a UniqueConstraint to the table.
    table.Constraints.Add(new UniqueConstraint(column));

    // Add five rows.
    DataRow newRow;

    for(int i = 0;i<5; i++)
    {
        // RowChanged event will occur for every addition.
        newRow= table.NewRow();
        newRow[0]= i;
        table.Rows.Add(newRow);
    }
    // AcceptChanges.
    table.AcceptChanges();

    // Invoke BeginEdit on each.
    Console.WriteLine(
        "\n Begin Edit and print original and proposed values \n");
    foreach(DataRow row in table.Rows)
    {

        row.BeginEdit();
        row[0]=(int) row[0]+10;
        Console.Write("\table Original \table" +
            row[0, DataRowVersion.Original]);
        Console.Write("\table Proposed \table" +
            row[0,DataRowVersion.Proposed] + "\n");
    }
    Console.WriteLine("\n");
    // Accept changes
    table.AcceptChanges();
    // Change two rows to identical values after invoking BeginEdit.
    table.Rows[0].BeginEdit();
    table.Rows[1].BeginEdit();
    table.Rows[0][0]= 100;
    table.Rows[1][0]=100;
    try
    {
        /* Now invoke EndEdit. This will cause the UniqueConstraint
           to be enforced.*/
        table.Rows[0].EndEdit();
        table.Rows[1].EndEdit();
    }
    catch(Exception e)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.",
            e.GetType());
    }
}

private void Row_Changed(object sender,
    System.Data.DataRowChangeEventArgs e)
{
    DataTable table = (DataTable)  sender;
    Console.WriteLine("RowChanged " + e.Action.ToString()
        + "\table" + e.Row.ItemArray[0]);
}
Private Sub DemonstrateRowBeginEdit()
    Dim table As New DataTable("table1")
    Dim column As New DataColumn("col1", Type.GetType("System.Int32"))
    AddHandler table.RowChanged, AddressOf Row_Changed
    table.Columns.Add(column)

    ' Add a UniqueConstraint to the table.
    table.Constraints.Add(New UniqueConstraint(column))

    ' Add five rows.
    Dim newRow As DataRow
       
    Dim i As Integer
    For i = 0 To 4
        ' RowChanged event will occur for every addition.
        newRow = table.NewRow()
        newRow(0) = i
        table.Rows.Add(newRow)
    Next i

    ' AcceptChanges.
    table.AcceptChanges()

    ' Invoke BeginEdit on each.
    Console.WriteLine(ControlChars.Cr _
       & " Begin Edit and print original and proposed values " _
       & ControlChars.Cr)
    Dim row As DataRow
    For Each row In  table.Rows           
        row.BeginEdit()
        row(0) = CInt(row(0)) & 10
        Console.Write(ControlChars.Tab & " Original " & ControlChars.Tab _
           & row(0, DataRowVersion.Original).ToString())
        Console.Write(ControlChars.Tab & " Proposed " & ControlChars.Tab _
           & row(0, DataRowVersion.Proposed).ToString() & ControlChars.Cr)
    Next row
    Console.WriteLine(ControlChars.Cr)

    ' Accept changes
    table.AcceptChanges()

    ' Change two rows to identical values after invoking BeginEdit.
    table.Rows(0).BeginEdit()
    table.Rows(1).BeginEdit()
    table.Rows(0)(0) = 100
    table.Rows(1)(0) = 100
    Try
        ' Now invoke EndEdit. This will cause the UniqueConstraint
        ' to be enforced.
        table.Rows(0).EndEdit()
        table.Rows(1).EndEdit()
    Catch e As Exception
    ' Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.", _
           e.GetType().ToString())
    End Try
End Sub

Private Sub Row_Changed _
(sender As Object, e As System.Data.DataRowChangeEventArgs)
    Dim table As DataTable = CType(sender, DataTable)
    Console.WriteLine("RowChanged " & e.Action.ToString() _
       & ControlChars.Tab & e.Row.ItemArray(0).ToString())
End Sub

설명

메서드를 BeginEdit 사용하여 를 DataRow 편집 모드로 전환합니다. 이 모드에서는 이벤트가 일시적으로 일시 중단되어 사용자가 유효성 검사 규칙을 트리거하지 않고 둘 이상의 행을 변경할 수 있습니다. 예를 들어 총 금액에 대한 열 값이 한 행의 직불 및 신용 열 값과 같은지 확인해야 하는 경우 각 행을 편집 모드로 전환하여 사용자가 값을 커밋하려고 할 때까지 행 값의 유효성 검사를 일시 중단할 수 있습니다.

메서드는 BeginEdit 사용자가 데이터 바인딩된 컨트롤 EndEdit 의 값을 변경할 때 암시적으로 호출됩니다. 메서드는 개체에 대한 DataTable 메서드를 AcceptChanges 호출할 때 암시적으로 호출됩니다. 이 편집 모드에서 는 DataRow 제안된 원래 값과 새 값의 표현을 저장합니다. 따라서 메서드가 EndEdit 호출되지 않은 한 속성의 Item[] 매개 변수에 대해 또는 DataRowVersion.Proposedversion 을 전달 DataRowVersion.Original 하여 원래 버전 또는 제안된 버전을 검색할 수 있습니다. 메서드를 호출하여 이 시점에서 편집 내용을 취소할 수도 있습니다 CancelEdit .

행에 원래 값이나 제안된 값이 포함되어 있는지 확인하려면 메서드를 호출합니다 HasVersion .

참고

메서드는 BeginEdit 이벤트를 일시적으로 일시 중단하지만 delete 작업은 일시 중단 RowChanging 하지 않습니다.

적용 대상

추가 정보