BindingManagerBase.EndCurrentEdit 方法

当在派生类中被重写时,结束当前编辑。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public MustOverride Sub EndCurrentEdit
用法
Dim instance As BindingManagerBase

instance.EndCurrentEdit
public abstract void EndCurrentEdit ()
public:
virtual void EndCurrentEdit () abstract
public abstract void EndCurrentEdit ()
public abstract function EndCurrentEdit ()

备注

仅当数据源实现了 IEditableObject 接口时,才支持此方法。在这种情况下,将会保存更改。如果对象未实现 IEditableObject 接口,将不保存对数据所做的更改。

示例

下面的代码示例演示 CancelCurrentEditEndCurrentEdit 方法。当调用 CancelCurrentEdit 方法时,对数据所做的更改将被丢弃。当调用 EndCurrentEdit 方法时,更改将被保留。

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
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:
   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)(get_BindingContext().get_Item(myDataView));

    // Gets the current row and changes a value. Then cancels the 
    // edit and thereby discards the changes.
    DataRowView tempRowView = (DataRowView)(myMgr.get_Current());
    
    Console.WriteLine("Original: {0}", tempRowView.get_Item("myCol"));
    tempRowView.set_Item("myCol", "These changes will be discarded");
    Console.WriteLine("Edit: {0}", tempRowView.get_Item("myCol"));
    myMgr.CancelCurrentEdit();
    Console.WriteLine("After CanceCurrentlEdit: {0}", 
        tempRowView.get_Item("myCol"));
} //CancelEdit

private void EndEdit()
{
    // Gets the CurrencyManager which is returned when the 
    // data source is a DataView.
    BindingManagerBase myMgr = 
        (CurrencyManager)(get_BindingContext().get_Item(myDataView));

    // Gets the current row and changes a value. Then ends the 
    // edit and thereby keeps the changes.
    DataRowView tempRowView = (DataRowView)(myMgr.get_Current());
    Console.WriteLine("Original: {0}", tempRowView.get_Item("myCol"));
    tempRowView.set_Item("myCol", "These changes will be kept");
    Console.WriteLine("Edit: {0}", tempRowView.get_Item("myCol"));
    myMgr.EndCurrentEdit();
    Console.WriteLine("After EndCurrentEdit: {0}", 
        tempRowView.get_Item("myCol"));
} //EndEdit

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

BindingManagerBase 类
BindingManagerBase 成员
System.Windows.Forms 命名空间
CancelCurrentEdit