Export (0) Print
Expand All

DataRowView.CancelEdit Method

Cancels an edit procedure.

[Visual Basic]
Public Overridable Sub CancelEdit() Implements _
   IEditableObject.CancelEdit
[C#]
public virtual void CancelEdit();
[C++]
public: virtual void CancelEdit();
[JScript]
public function CancelEdit();

Implements

IEditableObject.CancelEdit

Remarks

After calling CancelEdit, all changes to the row are rolled back. You can also roll back changes by calling RejectChanges on the parent DataTable.

Example

[Visual Basic, C#, C++] The following example edits a row in a DataView. The CancelEdit method is called to cancel the changes if the validation fails.

[Visual Basic] 
Private Sub EditDataRowView(drv As DataRowView, columnToEdit As String)
    drv.BeginEdit()
    drv(columnToEdit) = textBox1.Text
    ' Validate the input with a function.
    If ValidateCompanyName(drv(columnToEdit)) Then
        drv.EndEdit()
    Else
        drv.CancelEdit()
    End If
End Sub
    
Private Function ValidateCompanyName(valuetoCheck As Object) As Boolean
    ' Insert code to validate the value.
    Return True
End Function

[C#] 
private void EditDataRowView(DataRowView drv, string columnToEdit) {
   drv.BeginEdit();
   drv[columnToEdit] = textBox1.Text;
   // Validate the input with a function.
   if (ValidateCompanyName(drv[columnToEdit]))
      drv.EndEdit();   
   else
      drv.CancelEdit();
}

private bool ValidateCompanyName(object valuetoCheck) {
   // Insert code to validate the value.
   return true;
}

[C++] 
private:
 void EditDataRowView(DataRowView* drv, String* columnToEdit) {
    drv->BeginEdit();
    drv->Item[columnToEdit] = textBox1->Text;
    // Validate the input with a function.
    if (ValidateCompanyName(drv->Item[columnToEdit]))
       drv->EndEdit();   
    else
       drv->CancelEdit();
 }
 
 bool ValidateCompanyName(Object* /*valuetoCheck*/) {
    // Insert code to validate the value.
    return true;
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataRowView Class | DataRowView Members | System.Data Namespace | AcceptChanges | AllowDelete | AllowEdit | AllowNew | BeginEdit | DataRow | EndEdit | RowVersion

Show:
© 2014 Microsoft