DataRowView.BeginEdit 方法

定义

开始编辑过程。Begins an edit procedure.

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

实现

示例

下面的示例在中编辑行 DataRowViewThe following example edits a row in a DataRowView. BeginEdit在之前调用,然后调用 EndEditcalling the BeginEdit before, and EndEdit afterwards.

private void EditDataRowView(DataRowView rowView,
    string columnToEdit)
{
    rowView.BeginEdit();
    rowView[columnToEdit] = textBox1.Text;

    // Validate the input with a function.
    if (ValidateCompanyName(rowView[columnToEdit]))
        rowView.EndEdit();
    else
        rowView.CancelEdit();
}

private bool ValidateCompanyName(object valuetoCheck)
{
    // Insert code to validate the value.
    return true;
}
Private Sub EditDataRowView(rowView As DataRowView, _
    columnToEdit As String)
    rowView.BeginEdit()
    rowView(columnToEdit) = textBox1.Text

    ' Validate the input with a function.
    If ValidateCompanyName(rowView(columnToEdit)) Then
        rowView.EndEdit()
    Else
        rowView.CancelEdit()
    End If
End Sub
     
Private Function ValidateCompanyName( _
    valuetoCheck As Object) As Boolean
    ' Insert code to validate the value.
    Return True
End Function

注解

使用 AddNew 可添加 DataRowViewUse AddNew to add a DataRowView.

方法与的 BeginEdit 方法完全相同 DataRow.BeginEdit DataRowThe BeginEdit method is identical to the DataRow.BeginEdit method of the DataRow. 调用后 BeginEdit ,对所做的任何更改 DataRowView 都可以通过调用回滚 CancelEditAfter calling BeginEdit, any changes made to the DataRowView can be rolled back by calling CancelEdit. BeginEdit在允许用户更改行值之前调用方法。Call the BeginEdit method before allowing users to change row values. 更改值后,可通过将设置为来检索新的值 RowVersion DataRowVersion.ProposedAfter values have been changed, you retrieve the new values by setting the RowVersion to DataRowVersion.Proposed. 使用业务规则检查值,并根据需要通过调用来回滚更改, CancelEdit 或调用 EndEdit 以接受更改。Check the values with a business rule, and roll back the changes if needed by calling CancelEdit, or call EndEdit to accept the changes.

适用于

另请参阅