BindingManagerBase.CancelCurrentEdit Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Cuando se reemplaza en una clase derivada, se cancela la edición actual.
public:
abstract void CancelCurrentEdit();
public abstract void CancelCurrentEdit ();
abstract member CancelCurrentEdit : unit -> unit
Public MustOverride Sub CancelCurrentEdit ()
Ejemplos
En el ejemplo de código siguiente se muestran los CancelCurrentEdit métodos y EndCurrentEdit . Al llamar a los métodos, se descartan los CancelCurrentEdit cambios realizados en los datos. Cuando se llama al EndCurrentEdit método , se mantienen los cambios.
private:
void CancelEdit()
{
// Gets the CurrencyManager which is returned when the
// data source is a DataView.
BindingManagerBase^ myMgr = dynamic_cast<CurrencyManager^>(BindingContext[ myDataView ]);
// Gets the current row and changes a value. Then cancels the
// edit and thereby discards the changes.
DataRowView^ tempRowView = dynamic_cast<DataRowView^>(myMgr->Current);
Console::WriteLine( "Original: {0}", tempRowView[ "myCol" ] );
tempRowView[ "myCol" ] = "These changes will be discarded";
Console::WriteLine( "Edit: {0}", tempRowView[ "myCol" ] );
myMgr->CancelCurrentEdit();
Console::WriteLine( "After CanceCurrentlEdit: {0}", tempRowView[ "myCol" ] );
}
void EndEdit()
{
// Gets the CurrencyManager which is returned when the
// data source is a DataView.
BindingManagerBase^ myMgr = dynamic_cast<CurrencyManager^>(BindingContext[ myDataView ]);
// Gets the current row and changes a value. Then ends the
// edit and thereby keeps the changes.
DataRowView^ tempRowView = dynamic_cast<DataRowView^>(myMgr->Current);
Console::WriteLine( "Original: {0}", tempRowView[ "myCol" ] );
tempRowView[ "myCol" ] = "These changes will be kept";
Console::WriteLine( "Edit: {0}", tempRowView[ "myCol" ] );
myMgr->EndCurrentEdit();
Console::WriteLine( "After EndCurrentEdit: {0}", tempRowView[ "myCol" ] );
}
private void CancelEdit()
{
// Gets the CurrencyManager which is returned when the
// data source is a DataView.
BindingManagerBase myMgr =
(CurrencyManager) BindingContext[myDataView];
// Gets the current row and changes a value. Then cancels the
// edit and thereby discards the changes.
DataRowView tempRowView = (DataRowView) myMgr.Current;
Console.WriteLine("Original: {0}", tempRowView["myCol"]);
tempRowView["myCol"] = "These changes will be discarded";
Console.WriteLine("Edit: {0}", tempRowView["myCol"]);
myMgr.CancelCurrentEdit();
Console.WriteLine("After CanceCurrentlEdit: {0}",
tempRowView["myCol"]);
}
private void EndEdit()
{
// Gets the CurrencyManager which is returned when the
// data source is a DataView.
BindingManagerBase myMgr =
(CurrencyManager) BindingContext[myDataView];
// Gets the current row and changes a value. Then ends the
// edit and thereby keeps the changes.
DataRowView tempRowView = (DataRowView) myMgr.Current;
Console.WriteLine("Original: {0}", tempRowView["myCol"]);
tempRowView["myCol"] = "These changes will be kept";
Console.WriteLine("Edit: {0}", tempRowView["myCol"]);
myMgr.EndCurrentEdit();
Console.WriteLine("After EndCurrentEdit: {0}",
tempRowView["myCol"]);
}
Private Sub CancelEdit()
' Gets the CurrencyManager which is returned when the
' data source is a DataView.
Dim myMgr As BindingManagerBase = _
CType(BindingContext(myDataView), CurrencyManager)
' Gets the current row and changes a value. Then cancels the
' edit and thereby discards the changes.
Dim tempRowView As DataRowView = _
CType(myMgr.Current, DataRowView)
Console.WriteLine("Original: {0}", tempRowView("myCol"))
tempRowView("myCol") = "These changes will be discarded"
Console.WriteLine("Edit: {0}", tempRowView("myCol"))
myMgr.CancelCurrentEdit()
Console.WriteLine("After CanceCurrentlEdit: {0}", _
tempRowView("myCol"))
End Sub
Private Sub EndEdit()
' Gets the CurrencyManager which is returned when the
' data source is a DataView.
Dim myMgr As BindingManagerBase = _
CType(BindingContext(myDataView), CurrencyManager)
' Gets the current row and changes a value. Then ends the
' edit and thereby keeps the changes.
Dim tempRowView As DataRowView = _
CType(myMgr.Current, DataRowView)
Console.WriteLine("Original: {0}", tempRowView("myCol"))
tempRowView("myCol") = "These changes will be kept"
Console.WriteLine("Edit: {0}", tempRowView("myCol"))
myMgr.EndCurrentEdit()
Console.WriteLine("After EndCurrentEdit: {0}", _
tempRowView("myCol"))
End Sub
Comentarios
Este método solo se admite si el origen de datos implementa la IEditableObject interfaz . Si el objeto no implementa la IEditableObject interfaz, no se descartarán los cambios realizados en los datos.
Llamar al CancelCurrentEdit método hace que se produzca el Format evento.