Export (0) Print
Expand All

DataRow.CancelEdit Method

Cancels the current edit on the row.

[Visual Basic]
Public Sub CancelEdit()
[C#]
public void CancelEdit();
[C++]
public: void CancelEdit();
[JScript]
public function CancelEdit();

Exceptions

Exception Type Condition
InRowChangingEventException The method was called inside the RowChanging event.

Remarks

See the BeginEdit method for more details.

Example

[Visual Basic, C#, C++] The following example edits the value of one column in the last row of a DataGrid control. The example uses the BeginEdit, EndEdit, methods to edit the column's value and commit the change to the row.

[Visual Basic] 
Private Sub AcceptOrReject(ByVal myRow As DataRow)
   ' Use a function to validate the row's values.
   ' If the function returns true, end the edit; otherwise cancel it.
   If ValidateRow(myRow) Then
      myRow.EndEdit()
   Else
      myRow.CancelEdit()
   End If
End Sub

Private Function ValidateRow(ByVal myRow As DataRow) As Boolean
   Dim isValid As Boolean
   ' Insert code to validate the row values. Set the isValid variable.
   ValidateRow = isValid
End Function

[C#] 
private void AcceptOrReject(DataRow myRow){
   // Use a function to validate the row's values.
   // If the function returns true, end the edit; otherwise cancel it.
   if(ValidateRow(myRow))
      myRow.EndEdit();
   else
      myRow.CancelEdit();
}

private bool ValidateRow(DataRow thisRow){
   bool isValid = true; 
   // Insert code to validate the row values. Set the isValid variable.
   return isValid;
}

[C++] 
private:
 void AcceptOrReject(DataRow* myRow){
    // Use a function to validate the row's values.
    // If the function returns true, end the edit; otherwise cancel it.
    if(ValidateRow(myRow))
       myRow->EndEdit();
    else
       myRow->CancelEdit();
 }
 
 bool ValidateRow(DataRow* thisRow){
    bool isValid = true; 
    // Insert code to validate the row values. Set the isValid variable.
    return isValid;
 }

[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

DataRow Class | DataRow Members | System.Data Namespace | AcceptChanges | BeginEdit | DataViewRowState | EndEdit | HasVersion | Item | RowState

Show:
© 2014 Microsoft