System.Data Namespace DataRowView Class
Begins an edit procedure.
[ VB ]
NotOverridable Public Sub BeginEdit ( )
[ C# ]
public void BeginEdit ( );
[ C++ ]
public: __sealed void BeginEdit ( );
[ JScript ]
public function BeginEdit ( );
The BeginEdit method is identical to the DataRow.BeginEdit method of the DataRow. After calling BeginEdit, any changes made to the DataRowView can be rolled back by calling CancelEdit. Call the BeginEdit method before allowing users to change row values. After values have been changed, you retrieve the new values by setting the RowVersion to DataRowVersion.Proposed. Check the values with a business rule, and roll back the changes if needed by calling CancelEdit, or call EndEdit to accept the changes.
The following example edits a row in a DataRowView, calling the BeginEdit before, and EndEdit afterwards.
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 CancelEdit DataRow EndEdit