BindingContext.Contains 方法

定義

取得值,指出 BindingContext 是否含有指定的 BindingManagerBaseGets a value indicating whether the BindingContext contains the specified BindingManagerBase.

多載

Contains(Object)

取得值,指出 BindingContext 是否包含與指定資料來源相關的 BindingManagerBaseGets a value indicating whether the BindingContext contains the BindingManagerBase associated with the specified data source.

Contains(Object, String)

取得值,指出 BindingContext 是否包含與指定資料來源和資料成員相關的 BindingManagerBaseGets a value indicating whether the BindingContext contains the BindingManagerBase associated with the specified data source and data member.

Contains(Object)

取得值,指出 BindingContext 是否包含與指定資料來源相關的 BindingManagerBaseGets a value indicating whether the BindingContext contains the BindingManagerBase associated with the specified data source.

public:
 bool Contains(System::Object ^ dataSource);
public bool Contains (object dataSource);
member this.Contains : obj -> bool
Public Function Contains (dataSource As Object) As Boolean

參數

dataSource
Object

Object,代表資料來源。An Object that represents the data source.

傳回

如果 BindingContext 包含指定的 BindingManagerBase,則為 true,否則為 falsetrue if the BindingContext contains the specified BindingManagerBase; otherwise, false.

範例

下列程式碼範例會使用Contains方法,來判斷窗BindingManagerBase體上的每個控制項是否存在。The following code example uses the Contains method to determine whether a BindingManagerBase exists for each control on a form. 這個範例會將DataTable DataSet中的每個傳遞至方法。The example passes each DataTable in a DataSet to the method.

private:
   void TryContains( DataSet^ myDataSet )
   {
      // Test each DataTable in a DataSet to see if it is bound to a BindingManagerBase.
      for each ( DataTable^ thisTable in myDataSet->Tables )
      {
         Console::WriteLine( "{0}: {1}", thisTable->TableName, this->BindingContext->Contains( thisTable ) );
      }
   }
private void TryContains(DataSet myDataSet){
    // Test each DataTable in a DataSet to see if it is bound to a BindingManagerBase.
    foreach(DataTable thisTable in myDataSet.Tables){
       Console.WriteLine(thisTable.TableName + ": " + this.BindingContext.Contains(thisTable));
    }
 }

Private Sub TryContains(myDataSet As DataSet)
   Dim thisTable As DataTable
   ' Test each DataTable in a DataSet to see if it is bound to a BindingManagerBase.
   For Each thisTable In myDataSet.Tables
      Console.WriteLine(thisTable.TableName & ": " & Me.BindingContext.Contains(thisTable))
   Next
End Sub

備註

如需可能的資料來源清單,以及有關在控制項和資料來源之間建立系結的詳細資訊,請參閱類別。BindingSee the Binding class for a list of possible data sources and information about creating bindings between controls and data sources.

如需只使用資料來源傳回的BindingManagerBase相關資訊,請參閱屬性。Item[Object]See the Item[Object] property for information about returning a BindingManagerBase using only a data source.

另請參閱

Contains(Object, String)

取得值,指出 BindingContext 是否包含與指定資料來源和資料成員相關的 BindingManagerBaseGets a value indicating whether the BindingContext contains the BindingManagerBase associated with the specified data source and data member.

public:
 bool Contains(System::Object ^ dataSource, System::String ^ dataMember);
public bool Contains (object dataSource, string dataMember);
member this.Contains : obj * string -> bool
Public Function Contains (dataSource As Object, dataMember As String) As Boolean

參數

dataSource
Object

Object,代表資料來源。An Object that represents the data source.

dataMember
String

解析至特定 BindingManagerBase 所需的資訊。The information needed to resolve to a specific BindingManagerBase.

傳回

如果 BindingContext 包含指定的 BindingManagerBase,則為 true,否則為 falsetrue if the BindingContext contains the specified BindingManagerBase; otherwise, false.

範例

下列程式碼範例會使用Contains方法來測試是否有特定BindingManagerBase的存在,然後再嘗試透過Item[Object]屬性取得。The following code example uses the Contains method to test whether a specific BindingManagerBase exists before attempting to get it through the Item[Object] property.

private:
   void TryContainsDataMember( DataSet^ myDataSet )
   {
      bool trueorfalse;
      trueorfalse = this->BindingContext->Contains( myDataSet, "Suppliers" );
      Console::WriteLine( trueorfalse );
   }
private void TryContainsDataMember(DataSet myDataSet){
    bool trueorfalse;
    trueorfalse = this.BindingContext.Contains(myDataSet,"Suppliers");
    Console.WriteLine(trueorfalse.ToString());
 }

Private Sub TryContainsDataMember(myDataSet As DataSet)
   Dim trueorfalse As Boolean
   trueorfalse = Me.BindingContext.Contains(myDataSet, "Suppliers")
   Console.WriteLine(trueorfalse.ToString())
End Sub

備註

如需可能的資料來源清單,以及有關在控制項和資料來源之間建立系結的詳細資訊,請參閱類別。BindingSee the Binding class for a list of possible data sources and for information about creating bindings between controls and data sources.

如需使用資料來源和資料成員BindingManagerBase傳回的詳細資訊,請參閱屬性。Item[Object]See the Item[Object] property for information about returning a BindingManagerBase using a data source and data member.

另請參閱

適用於