System.Data Namespace DataRowView Class
Cancels an edit procedure.
[ VB ]
NotOverridable Public Sub CancelEdit ( )
[ C# ]
public void CancelEdit ( );
[ C++ ]
public: __sealed void CancelEdit ( );
[ JScript ]
public function CancelEdit ( );
After calling CancelEdit, all changes to the row are rolled back. You can also roll back changes by calling RejectChanges on the parent DataTable.
The following example edits a row in a DataView. The CancelEdit method is called to cancel the changes if the validation fails.
private void EditDataRowView ( DataRowView drv, string colToEdit ) {
drv.BeginEdit ( );
drv [ colToEdit ] = textBox1.Text;
// validate the input with a function.
if ( ValidateCompanyName ( drv [ colToEdit ] ) )
drv.EndEdit ( );
else
drv.CancelEdit ( );
}
private bool ValidateCompanyName ( object valuetoCheck ) {
// insert code to validate the value.
return true;
}
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# |
VB |
DataRowView Members AcceptChanges AllowDelete AllowEdit AllowNew BeginEdit DataRow EndEdit RowVersion