BindingManagerBase 類別

定義

管理繫結至相同資料來源和資料成員的所有 Binding 物件。Manages all Binding objects that are bound to the same data source and data member. 這個類別是抽象的。This class is abstract.

public ref class BindingManagerBase abstract
public abstract class BindingManagerBase
type BindingManagerBase = class
Public MustInherit Class BindingManagerBase
繼承
BindingManagerBase
衍生

範例

下列程式碼範例會使用, BindingContext BindingManagerBase 針對特定資料來源傳回。The following code example uses the BindingContext to return a BindingManagerBase for a specific data source. (範例假設您已 myBindingManagerBase 在模組的宣告區段中宣告。 ) 此範例會將事件委派加入至 CurrentChangedPositionChanged 事件。(The example assumes you have declared myBindingManagerBase in the Declarations section of the module.) The example then adds event delegates to the CurrentChanged and PositionChanged events. 最後,此範例包含四個方法 (MoveNextMovePreviousMoveFirstMoveLast) 來遞增或遞減 Position 屬性,並將設定 Position 為清單中的第一個或最後一個資料列。Lastly, the example contains four methods (MoveNext, MovePrevious, MoveFirst, and MoveLast) that increment or decrement the Position property, and set the Position to the first or last row in the list. 清單中的最後一個資料列是藉由使用 Count 屬性來決定。The last row in the list is determined by using the Count property.

void GetBindingManagerBase()
{
   
   /* CustomersToOrders is the RelationName of a DataRelation. 
      Therefore, the list maintained by the BindingManagerBase is the
      list of orders that belong to a specific customer in the 
      DataTable named Customers, found in DataSet1. */
   myBindingManagerBase = this->BindingContext[DataSet1, "Customers.CustomersToOrders"];
   
   // Adds delegates to the CurrentChanged and PositionChanged events.
   myBindingManagerBase->PositionChanged += gcnew EventHandler( this, &Form1::BindingManagerBase_PositionChanged );
   myBindingManagerBase->CurrentChanged += gcnew EventHandler( this, &Form1::BindingManagerBase_CurrentChanged );
}

void BindingManagerBase_PositionChanged( Object^ sender, EventArgs^ /*e*/ )
{
   
   // Prints the new Position of the BindingManagerBase.
   Console::Write( "Position Changed: " );
   Console::WriteLine( (dynamic_cast<BindingManagerBase^>(sender))->Position );
}

void BindingManagerBase_CurrentChanged( Object^ sender, EventArgs^ /*e*/ )
{
   
   // Prints the new value of the current object.
   Console::Write( "Current Changed: " );
   Console::WriteLine( (dynamic_cast<BindingManagerBase^>(sender))->Current );
}

void MoveNext()
{
   
   // Increments the Position property value by one.
   myBindingManagerBase->Position = myBindingManagerBase->Position + 1;
}

void MovePrevious()
{
   
   // Decrements the Position property value by one.
   myBindingManagerBase->Position = myBindingManagerBase->Position - 1;
}

void MoveFirst()
{
   
   // Goes to the first row in the list.
   myBindingManagerBase->Position = 0;
}

void MoveLast()
{
   
   // Goes to the last row in the list.
   myBindingManagerBase->Position = myBindingManagerBase->Count - 1;
}

private void GetBindingManagerBase()
{
   /* CustomersToOrders is the RelationName of a DataRelation. 
   Therefore, the list maintained by the BindingManagerBase is the
   list of orders that belong to a specific customer in the 
   DataTable named Customers, found in DataSet1. */
   myBindingManagerBase = 
   this.BindingContext[DataSet1, "Customers.CustomersToOrders"];

   // Adds delegates to the CurrentChanged and PositionChanged events.
   myBindingManagerBase.PositionChanged += 
   new EventHandler(BindingManagerBase_PositionChanged);
   myBindingManagerBase.CurrentChanged +=
   new EventHandler(BindingManagerBase_CurrentChanged);
}

private void BindingManagerBase_PositionChanged
(object sender, EventArgs e)
{
   // Prints the new Position of the BindingManagerBase.
   Console.Write("Position Changed: ");
   Console.WriteLine(((BindingManagerBase)sender).Position);
}

private void BindingManagerBase_CurrentChanged
(object sender, EventArgs e)
{
   // Prints the new value of the current object.
   Console.Write("Current Changed: ");
   Console.WriteLine(((BindingManagerBase)sender).Current);
}

private void MoveNext()
{
   // Increments the Position property value by one.
   myBindingManagerBase.Position += 1;
}

private void MovePrevious()
{
   // Decrements the Position property value by one.
   myBindingManagerBase.Position -= 1;
}

private void MoveFirst()
{
   // Goes to the first row in the list.
   myBindingManagerBase.Position = 0;
}

private void MoveLast()
{
   // Goes to the last row in the list.
   myBindingManagerBase.Position = 
   myBindingManagerBase.Count - 1;
}

Private Sub GetBindingManagerBase
   ' CustomersToOrders is the RelationName of a DataRelation.
   ' Therefore, the list maintained by the BindingManagerBase is the
   ' list of orders that belong to a specific customer in the
   ' DataTable named Customers, found in DataSet.
   myBindingManagerBase = Me.BindingContext(DataSet1, _
   "Customers.CustomersToOrders")

   ' Adds delegates to the CurrentChanged and PositionChanged events.
   AddHandler myBindingManagerBase.PositionChanged, _
   AddressOf BindingManagerBase_PositionChanged
   AddHandler myBindingManagerBase.CurrentChanged, _
   AddressOf BindingManagerBase_CurrentChanged
End Sub

Private Sub BindingManagerBase_PositionChanged _
(sender As Object, e As EventArgs)

   ' Prints the new Position of the BindingManagerBase.
   Console.Write("Position Changed: ")
   Console.WriteLine(CType(sender, BindingManagerBase).Position)
End Sub

Private Sub BindingManagerBase_CurrentChanged _
(sender As Object, e As EventArgs)

   ' Prints the new value of the current object.
   Console.Write("Current Changed: ")
   Console.WriteLine(CType(sender, BindingManagerBase).Current)
End Sub

Private Sub MoveNext
   ' Increments the Position property value by one.
   myBindingManagerBase.Position += 1
End Sub

Private Sub MovePrevious
   ' Decrements the Position property value by one.
   myBindingManagerBase.Position -= 1
End Sub

Private Sub MoveFirst
   ' Goes to the first row in the list.
   myBindingManagerBase.Position = 0
End Sub

Private Sub MoveLast
   ' Goes to the last row in the list.
   myBindingManagerBase.Position = _
   myBindingManagerBase.Count - 1
End Sub

備註

可在系結 BindingManagerBase 至相同資料來源的 Windows Form 上,同步處理資料繫結控制項。The BindingManagerBase enables the synchronization of data-bound controls on a Windows Form that are bound to the same data source. (如需簡單地將控制項系結至資料來源的詳細資訊,請參閱 Binding ) 。例如,假設表單包含兩個系結 TextBox 至相同資料來源但不同資料行的控制項。(For more information about simple binding a control to a data source, see the Binding class.) For example, suppose that a form contains two TextBox controls that are bound to the same data source but to different columns. 資料來源可能是 DataTable 包含客戶名稱的,而資料行可能包含名字和姓氏。The data source might be a DataTable that contains customer names, while the columns might contain the first and last names. 這兩個控制項必須進行同步處理,才能為相同的客戶顯示正確的名字和姓氏。The two controls must be synchronized in order to display the correct first and last names together for the same customer. 繼承自類別的,會藉 CurrencyManager BindingManagerBase 由維護資料來源中目前專案的指標來完成這項同步處理。The CurrencyManager, which inherits from the BindingManagerBase class, accomplishes this synchronization by maintaining a pointer to the current item in the data source. TextBox控制項會系結至目前的專案,使其顯示相同資料列的資訊。The TextBox controls are bound to the current item so they display the information for the same row. 當目前專案變更時,會 CurrencyManager 通知所有繫結控制項,讓他們可以重新整理其資料。When the current item changes, the CurrencyManager notifies all the bound controls so that they can refresh their data. 此外,您可以設定 Position 屬性,以指定控制項指向之的資料列 DataTableFurthermore, you can set the Position property to specify the row in the DataTable that the controls point to. 若要判斷資料來源中有多少資料列,請使用 Count 屬性。To determine how many rows exist in the data source, use the Count property.

CurrencyManager是必要的,因為資料來源不一定會維護目前的專案指標。The CurrencyManager is necessary because data sources do not necessarily maintain a current-item pointer. 例如,陣列和 ArrayList 物件可以是資料來源,但是沒有會傳回目前專案的屬性。For instance, arrays and ArrayList objects can be data sources, but they do not have a property that returns the current item. 若要取得目前的專案,請使用 Current 屬性。To get the current item, use the Current property.

PropertyManager也會繼承自 BindingManagerBase ,而且會用來維護物件的目前屬性,而不是資料來源中目前物件的屬性。The PropertyManager also inherits from the BindingManagerBase, and it is used to maintain the current property of an object, rather than the property of a current object in a data source. 基於這個理由,嘗試設定的 PositionCount 屬性 PropertyManager 沒有任何作用。For this reason, trying to set the Position or Count property for a PropertyManager has no effect.

若要建立 BindingManagerBase ,請使用 BindingContext 類別,此類別會 CurrencyManager PropertyManager 根據所管理的資料來源,傳回或。To create a BindingManagerBase, use the BindingContext class, which returns either a CurrencyManager or a PropertyManager, depending on the data source being managed.

建議程式設計人員將控制項直接系結至 BindingSource 元件,以做為實際目標資料來源的資料來源和資料連線器。Solutions programmers are encouraged to bind controls directly to a BindingSource component, which acts as both a data source and data connector to the actual target data source. BindingSource 大幅簡化簡單和複雜的資料系結,包括管理控制項和其目標之間的貨幣。BindingSource greatly simplifies both simple and complex data binding, including managing currency between the control and its target.

給實施者的注意事項

當您繼承自時 BindingManagerBase ,您必須覆寫下列抽象成員: AddNew()Count 、、、、、、、、、 CancelCurrentEdit() Current EndCurrentEdit() GetItemProperties() OnCurrentChanged(EventArgs) Position RemoveAt(Int32) ResumeBinding() SuspendBinding()UpdateIsBinding()When you inherit from BindingManagerBase, you must override the following abstract members: AddNew(), Count, CancelCurrentEdit(), Current, EndCurrentEdit(), GetItemProperties(), OnCurrentChanged(EventArgs), Position, RemoveAt(Int32), ResumeBinding(), SuspendBinding(), and UpdateIsBinding().

建構函式

BindingManagerBase()

初始化 BindingManagerBase 類別的新執行個體。Initializes a new instance of the BindingManagerBase class.

欄位

onCurrentChangedHandler

指定 CurrentChanged 事件的事件處理常式。Specifies the event handler for the CurrentChanged event.

onPositionChangedHandler

指定 PositionChanged 事件的事件處理常式。Specifies the event handler for the PositionChanged event.

屬性

Bindings

取得受管理的繫結集合。Gets the collection of bindings being managed.

Count

在衍生類別中覆寫時,取得 BindingManagerBase 管理的資料列數目。When overridden in a derived class, gets the number of rows managed by the BindingManagerBase.

Current

當在衍生類別中覆寫時,取得目前物件。When overridden in a derived class, gets the current object.

IsBindingSuspended

取得值,指出繫結作業是否已暫止。Gets a value indicating whether binding is suspended.

Position

當在衍生類別中覆寫時,取得或設定控制項 (繫結至這個資料來源) 所指向基礎清單中的位置。When overridden in a derived class, gets or sets the position in the underlying list that controls bound to this data source point to.

方法

AddNew()

當在衍生類別中覆寫時,加入新項目至基礎清單中。When overridden in a derived class, adds a new item to the underlying list.

CancelCurrentEdit()

當在衍生類別中覆寫時,取消目前的編輯。When overridden in a derived class, cancels the current edit.

EndCurrentEdit()

當在衍生類別中覆寫時,結束目前的編輯。When overridden in a derived class, ends the current edit.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetItemProperties()

當在衍生類別中覆寫時,取得繫結的屬性描述項集合。When overridden in a derived class, gets the collection of property descriptors for the binding.

GetItemProperties(ArrayList, ArrayList)

使用指定的 ArrayList,取得繫結的屬性描述項集合。Gets the collection of property descriptors for the binding using the specified ArrayList.

GetItemProperties(Type, Int32, ArrayList, ArrayList)

取得由這個 BindingManagerBase 所管理項目的屬性清單。Gets the list of properties of the items managed by this BindingManagerBase.

GetListName(ArrayList)

當在衍生類別中覆寫時,取得提供資料給繫結的清單名稱。When overridden in a derived class, gets the name of the list supplying the data for the binding.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnBindingComplete(BindingCompleteEventArgs)

引發 BindingComplete 事件。Raises the BindingComplete event.

OnCurrentChanged(EventArgs)

引發 CurrentChanged 事件。Raises the CurrentChanged event.

OnCurrentItemChanged(EventArgs)

引發 CurrentItemChanged 事件。Raises the CurrentItemChanged event.

OnDataError(Exception)

引發 DataError 事件。Raises the DataError event.

PullData()

從資料繫結的控制項取出資料送入資料來源,而不需傳回任何資訊。Pulls data from the data-bound control into the data source, returning no information.

PushData()

將資料來源中的資料送入資料繫結的控制項,而不需傳回任何資訊。Pushes data from the data source into the data-bound control, returning no information.

RemoveAt(Int32)

當在衍生類別中覆寫時,刪除位於基礎清單中指定索引處的資料列。When overridden in a derived class, deletes the row at the specified index from the underlying list.

ResumeBinding()

當在衍生類別中覆寫時,繼續資料繫結 (Data Binding)。When overridden in a derived class, resumes data binding.

SuspendBinding()

當在衍生類別中覆寫時,暫止資料繫結。When overridden in a derived class, suspends data binding.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
UpdateIsBinding()

當在衍生類別中覆寫時,更新繫結。When overridden in a derived class, updates the binding.

事件

BindingComplete

發生於資料繫結作業完成時。Occurs at the completion of a data-binding operation.

CurrentChanged

發生於目前繫結的項目變更時。Occurs when the currently bound item changes.

CurrentItemChanged

發生於目前繫結的項目之狀態變更時。Occurs when the state of the currently bound item changes.

DataError

Exception 以無訊息模式處理 BindingManagerBase 時發生。Occurs when an Exception is silently handled by the BindingManagerBase.

PositionChanged

發生於 Position 屬性的值已變更後。Occurs after the value of the Position property has changed.

適用於

另請參閱