BindingManagerBase.EndCurrentEdit 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当在派生类中被重写时,结束当前编辑。
public:
abstract void EndCurrentEdit();
public abstract void EndCurrentEdit ();
abstract member EndCurrentEdit : unit -> unit
Public MustOverride Sub EndCurrentEdit ()
示例
下面的代码示例演示 CancelCurrentEdit 和 EndCurrentEdit 方法。 调用 CancelCurrentEdit 方法时,将放弃对数据所做的更改。 调用 EndCurrentEdit 方法时,将保留更改。
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
注解
仅当数据源实现 接口时, IEditableObject 才支持此方法。 在这种情况下,将保存更改。 如果对象未实现 IEditableObject 接口,则不会保存对数据所做的更改。