BindingManagerBase 類別

定義

管理繫結至相同資料來源和資料成員的所有 Binding 物件。 這個類別是抽象的。

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

範例

下列程式碼範例會使用 BindingContext 傳回 BindingManagerBase 特定資料來源的 。 (此範例假設您已在 module.) 的宣告區段中宣告 myBindingManagerBase 此範例,然後將事件委派新增至 CurrentChangedPositionChanged 事件。 最後,此範例包含四個方法 (、、 和 MoveLast) 遞增或遞減 Position 屬性,並將 設定 Position 為清單中的第一個或最後一個資料 MoveFirst 列。 MovePreviousMoveNext 清單中的最後一個資料列是使用 Count 屬性來決定。

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 上同步處理資料繫結控制項。 (如需將控制項系結至資料來源的詳細資訊,請參閱 Binding class.) 例如,假設表單包含兩 TextBox 個系結至相同資料來源但系結至不同資料行的控制項。 資料來源可能是 DataTable 包含客戶名稱的 ,而資料行可能包含名字和姓氏。 這兩個控制項必須同步處理,才能為相同的客戶一起顯示正確的名字和姓氏。 繼承自 類別的 BindingManagerBaseCurrencyManager 藉由維護資料來源中目前專案的指標來完成這項同步處理。 控制項 TextBox 會系結至目前的專案,以便顯示相同資料列的資訊。 當目前的專案變更時,會 CurrencyManager 通知所有繫結控制項,以便重新整理其資料。 此外,您可以設定 Position 屬性,以指定控制項指向的資料 DataTable 列。 若要判斷資料來源中有多少個數據列,請使用 Count 屬性。

CurrencyManager是必要的,因為資料來源不一定會維護目前的專案指標。 例如,陣列和 ArrayList 物件可以是資料來源,但它們沒有傳回目前專案的屬性。 若要取得目前的專案,請使用 Current 屬性。

PropertyManager也會繼承自 BindingManagerBase ,並且用來維護物件的目前屬性,而不是資料來源中目前物件的 屬性。 基於這個理由,嘗試設定 Position 的 或 Count 屬性 PropertyManager 沒有任何作用。

若要建立 BindingManagerBase ,請使用 BindingContext 類別,其會根據所管理的資料來源傳回 CurrencyManagerPropertyManager

我們鼓勵解決方案程式設計人員將控制項直接系結至 BindingSource 元件,這同時作為資料來源和資料連線器,以作為實際目標資料來源。 BindingSource 大幅簡化簡單和複雜的資料系結,包括管理控制項與其目標之間的貨幣。

給實施者的注意事項

當您繼承自 BindingManagerBase 時,必須覆寫下列抽象成員: AddNew() 、、 CountGetItemProperties()CancelCurrentEdit()OnCurrentChanged(EventArgs)EndCurrentEdit()Current 、、 RemoveAt(Int32)ResumeBinding()PositionSuspendBinding() 和 。 UpdateIsBinding()

建構函式

BindingManagerBase()

初始化 BindingManagerBase 類別的新執行個體。

欄位

onCurrentChangedHandler

指定 CurrentChanged 事件的事件處理常式。

onPositionChangedHandler

指定 PositionChanged 事件的事件處理常式。

屬性

Bindings

取得受管理的繫結集合。

Count

在衍生類別中覆寫時,取得 BindingManagerBase 管理的資料列數目。

Current

當在衍生類別中覆寫時,取得目前物件。

IsBindingSuspended

取得值,指出繫結作業是否已暫止。

Position

當在衍生類別中覆寫時,取得或設定控制項 (繫結至這個資料來源) 所指向基礎清單中的位置。

方法

AddNew()

當在衍生類別中覆寫時,加入新項目至基礎清單中。

CancelCurrentEdit()

當在衍生類別中覆寫時,取消目前的編輯。

EndCurrentEdit()

當在衍生類別中覆寫時,結束目前的編輯。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetItemProperties()

當在衍生類別中覆寫時,取得繫結的屬性描述項集合。

GetItemProperties(ArrayList, ArrayList)

使用指定的 ArrayList,取得繫結的屬性描述項集合。

GetItemProperties(Type, Int32, ArrayList, ArrayList)

取得由這個 BindingManagerBase 所管理項目的屬性清單。

GetListName(ArrayList)

當在衍生類別中覆寫時,取得提供資料給繫結的清單名稱。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnBindingComplete(BindingCompleteEventArgs)

引發 BindingComplete 事件。

OnCurrentChanged(EventArgs)

引發 CurrentChanged 事件。

OnCurrentItemChanged(EventArgs)

引發 CurrentItemChanged 事件。

OnDataError(Exception)

引發 DataError 事件。

PullData()

從資料繫結的控制項取出資料送入資料來源,而不需傳回任何資訊。

PushData()

將資料來源中的資料送入資料繫結的控制項,而不需傳回任何資訊。

RemoveAt(Int32)

當在衍生類別中覆寫時,刪除位於基礎清單中指定索引處的資料列。

ResumeBinding()

當在衍生類別中覆寫時,繼續資料繫結 (Data Binding)。

SuspendBinding()

當在衍生類別中覆寫時,暫止資料繫結。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
UpdateIsBinding()

當在衍生類別中覆寫時,更新繫結。

事件

BindingComplete

發生於資料繫結作業完成時。

CurrentChanged

發生於目前繫結的項目變更時。

CurrentItemChanged

發生於目前繫結的項目之狀態變更時。

DataError

Exception 以無訊息模式處理 BindingManagerBase 時發生。

PositionChanged

發生於 Position 屬性的值已變更後。

適用於

另請參閱