BindingContext.Item[] Tulajdonság

Definíció

Túlterhelések

Name Description
Item[Object, String]

BindingManagerBase Lekéri a megadott adatforráshoz és adattaghoz társított adatokat.

Item[Object]

Lekéri a BindingManagerBase megadott adatforráshoz társított adatokat.

Item[Object, String]

Forrás:
BindingContext.cs
Forrás:
BindingContext.cs
Forrás:
BindingContext.cs
Forrás:
BindingContext.cs
Forrás:
BindingContext.cs

BindingManagerBase Lekéri a megadott adatforráshoz és adattaghoz társított adatokat.

public:
 property System::Windows::Forms::BindingManagerBase ^ default[System::Object ^, System::String ^] { System::Windows::Forms::BindingManagerBase ^ get(System::Object ^ dataSource, System::String ^ dataMember); };
public System.Windows.Forms.BindingManagerBase this[object dataSource, string dataMember] { get; }
public System.Windows.Forms.BindingManagerBase this[object dataSource, string? dataMember] { get; }
member this.Item(obj * string) : System.Windows.Forms.BindingManagerBase
Default Public ReadOnly Property Item(dataSource As Object, dataMember As String) As BindingManagerBase

Paraméterek

dataSource
Object

Az adott BindingManagerBaseadatforráshoz társított adatforrás.

dataMember
String

Egy navigációs útvonal, amely egy adott információra feloldja az adatokat BindingManagerBase.

Tulajdonság értéke

A BindingManagerBase megadott adatforrás és adattag.

Kivételek

A megadott dataMember nem létezik az adatforráson belül.

Példák

Az alábbi példakód bemutatja, hogyan használható az Item[] adott kötés lekérésére BindingManagerBase . Azt is bemutatja, hogyan kezelheti az BindingComplete eseményt BindingManagerBase annak érdekében, hogy az ugyanazon adatforráshoz kötött vezérlők szinkronizálva maradjanak az egyik vezérlőérték módosításakor. A példa futtatásához illessze be a kódot egy Windows űrlapba, és hívja meg a InitializeControlsAndData metódust az űrlap konstruktorából vagy Load eseménykezelési módszerből.

private void InitializeControlsAndData()
{
    // Initialize the controls and set location, size and 
    // other basic properties.
    this.dataGridView1 = new DataGridView();
    
    this.textBox1 = new TextBox();
    this.textBox2 = new TextBox();
    this.dataGridView1.ColumnHeadersHeightSizeMode =
        DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    this.dataGridView1.Dock = DockStyle.Top;
    this.dataGridView1.Location = new Point(0, 0);
    this.dataGridView1.Size = new Size(292, 150);
    this.textBox1.Location = new Point(132, 156);
    this.textBox1.Size = new Size(100, 20);
    this.textBox2.Location = new Point(12, 156);
    this.textBox2.Size = new Size(100, 20);
    this.ClientSize = new Size(292, 266);
    this.Controls.Add(this.textBox2);
    this.Controls.Add(this.textBox1);
    this.Controls.Add(this.dataGridView1);

    // Declare the DataSet and add a table and column.
    DataSet set1 = new DataSet();
    set1.Tables.Add("Menu");
    set1.Tables[0].Columns.Add("Beverages");

    // Add some rows to the table.
    set1.Tables[0].Rows.Add("coffee");
    set1.Tables[0].Rows.Add("tea");
    set1.Tables[0].Rows.Add("hot chocolate");
    set1.Tables[0].Rows.Add("milk");
    set1.Tables[0].Rows.Add("orange juice");

    // Add the control data bindings.
    dataGridView1.DataSource = set1;
    dataGridView1.DataMember = "Menu";
    textBox1.DataBindings.Add("Text", set1,
        "Menu.Beverages", true, DataSourceUpdateMode.OnPropertyChanged);
    textBox2.DataBindings.Add("Text", set1,
        "Menu.Beverages", true, DataSourceUpdateMode.OnPropertyChanged);

    BindingManagerBase bmb = this.BindingContext[set1, "Menu"];
    bmb.BindingComplete += new BindingCompleteEventHandler(bmb_BindingComplete);
}

private void bmb_BindingComplete(object sender, BindingCompleteEventArgs e)
{
    // Check if the data source has been updated, and that no error has occurred.
    if (e.BindingCompleteContext ==
        BindingCompleteContext.DataSourceUpdate && e.Exception == null)

        // If not, end the current edit.
        e.Binding.BindingManagerBase.EndCurrentEdit(); ;
}
Dim WithEvents bmb As BindingManagerBase

Private Sub InitializeControlsAndData() 
    ' Initialize the controls and set location, size and 
    ' other basic properties.
    Me.dataGridView1 = New DataGridView()
    
    Me.textBox1 = New TextBox()
    Me.textBox2 = New TextBox()
    Me.dataGridView1.ColumnHeadersHeightSizeMode = _
        DataGridViewColumnHeadersHeightSizeMode.AutoSize
    Me.dataGridView1.Dock = DockStyle.Top
    Me.dataGridView1.Location = New Point(0, 0)
    Me.dataGridView1.Size = New Size(292, 150)
    Me.textBox1.Location = New Point(132, 156)
    Me.textBox1.Size = New Size(100, 20)
    Me.textBox2.Location = New Point(12, 156)
    Me.textBox2.Size = New Size(100, 20)
    Me.ClientSize = New Size(292, 266)
    Me.Controls.Add(Me.textBox2)
    Me.Controls.Add(Me.textBox1)
    Me.Controls.Add(Me.dataGridView1)
    
    ' Declare the DataSet and add a table and column.
    Dim set1 As New DataSet()
    set1.Tables.Add("Menu")
    set1.Tables(0).Columns.Add("Beverages")
    
    ' Add some rows to the table.
    set1.Tables(0).Rows.Add("coffee")
    set1.Tables(0).Rows.Add("tea")
    set1.Tables(0).Rows.Add("hot chocolate")
    set1.Tables(0).Rows.Add("milk")
    set1.Tables(0).Rows.Add("orange juice")

    ' Add the control data bindings.
    dataGridView1.DataSource = set1
    dataGridView1.DataMember = "Menu"
    textBox1.DataBindings.Add("Text", set1, "Menu.Beverages", _
        True, DataSourceUpdateMode.OnPropertyChanged)
    textBox2.DataBindings.Add("Text", set1, "Menu.Beverages", _
        True, DataSourceUpdateMode.OnPropertyChanged)

    ' Get the BindingManagerBase for this binding.
    bmb = Me.BindingContext(set1, "Menu")

End Sub

Private Sub bmb_BindingComplete(ByVal sender As Object, ByVal e As BindingCompleteEventArgs) _
    Handles bmb.BindingComplete

    ' Check if the data source has been updated, and that no error has occurred.
    If e.BindingCompleteContext = BindingCompleteContext.DataSourceUpdate _
        AndAlso e.Exception Is Nothing Then

        ' If not, end the current edit.
        e.Binding.BindingManagerBase.EndCurrentEdit()
    End If
End Sub

Megjegyzések

Ezt a túlterhelést akkor használja, ha az BindingManagerBase olyan objektumok készletét Binding kezeli, amelyekhez az adatforrás több objektumot tartalmaz. Egy objektum például DataSet több DataTable objektumot is tartalmazhat, amelyeket DataRelation objektumok kapcsolnak össze. Ilyen esetben a navigációs útvonal szükséges ahhoz, hogy a BindingContext helyes BindingManagerBaseértéket adja vissza.

Note

A Item[] tulajdonság mindig egy értéket ad vissza BindingManagerBase, ha a dataMember paraméter érvényes. Soha nem fog visszatérni null.

Tekintse meg a Binding lehetséges adatforrások listáját, valamint a vezérlők és adatforrások közötti kötések létrehozásával kapcsolatos információkat.

Ha a kívánt BindingManagerBase lista kezelhető, a navigációs útvonalnak egy listával is végződnie kell. Az alábbi C#-kód például egy TextBox vezérlőelemet a rendelési dátumhoz köt egy rendeléstáblában. A navigációs útvonal tartalmazza a TableName, a RelationName, és a ColumnName. A BindingManagerBase lekérést azonban csak az TableName és RelationName (listára feloldó) paranccsel lehet lekérni.

// The navigation path for a Binding ends with a property.
textBox1.DataBindings.Add
("Text", dataSet1, "Customers.custToOrders.OrderDate");
// The navigation path for the BindingManagerBase ends with a list.
BindingManagerBase bmOrders = this.BindingContext
[dataSet1, "Customers.custToOrders"];

A visszatéréskor BindingManagerBaseugyanazt az adatforrást kell használnia, mint a Binding navigációs útvonalat, és csak a navigációs útvonalat kell módosítania.

Contains A metódus használatával állapítsa meg, hogy a kívánt BindingManagerBase már létezik-e.

Lásd még

A következőre érvényes:

Item[Object]

Forrás:
BindingContext.cs
Forrás:
BindingContext.cs
Forrás:
BindingContext.cs
Forrás:
BindingContext.cs
Forrás:
BindingContext.cs

Lekéri a BindingManagerBase megadott adatforráshoz társított adatokat.

public:
 property System::Windows::Forms::BindingManagerBase ^ default[System::Object ^] { System::Windows::Forms::BindingManagerBase ^ get(System::Object ^ dataSource); };
public System.Windows.Forms.BindingManagerBase this[object dataSource] { get; }
member this.Item(obj) : System.Windows.Forms.BindingManagerBase
Default Public ReadOnly Property Item(dataSource As Object) As BindingManagerBase

Paraméterek

dataSource
Object

Az adott BindingManagerBaseadatforráshoz társított adatforrás.

Tulajdonság értéke

A BindingManagerBase a megadott adatforráshoz.

Példák

Az alábbi példakód három BindingManagerBase objektumot ad vissza: egyet egyhezDataView, egyet egyhezArrayList, egyet pedig egy DataSource vezérlőelemhez tartozó objektumnak BindingTextBox.

void ReturnBindingManagerBase()
{
   
   // Get the BindingManagerBase for a DataView. 
   BindingManagerBase^ bmCustomers = this->BindingContext[ myDataView ];
   
   /* Get the BindingManagerBase for an ArrayList. */
   BindingManagerBase^ bmOrders = this->BindingContext[ myArrayList ];
   
   // Get the BindingManagerBase for a TextBox control.
   BindingManagerBase^ baseArray = this->BindingContext[ textBox1->DataBindings[ nullptr ]->DataSource ];
}
private void ReturnBindingManagerBase()
{
   // Get the BindingManagerBase for a DataView. 
   BindingManagerBase bmCustomers = 
   this.BindingContext [myDataView];

   /* Get the BindingManagerBase for an ArrayList. */ 
   BindingManagerBase bmOrders = 
   this.BindingContext[myArrayList];

   // Get the BindingManagerBase for a TextBox control.
   BindingManagerBase baseArray = 
   this.BindingContext[textBox1.DataBindings[0].DataSource];
}
Private Sub ReturnBindingManagerBase()
   ' Get the BindingManagerBase for a DataView. 
   Dim bmCustomers As BindingManagerBase = _
      Me.BindingContext(myDataView)

   ' Get the BindingManagerBase for an ArrayList.
   Dim bmOrders As BindingManagerBase = _
      Me.BindingContext(myArrayList)

   ' Get the BindingManagerBase for a TextBox control.
   Dim baseArray As BindingManagerBase = _
      Me.BindingContext(Text1.DataBindings(0).DataSource)
End Sub

Megjegyzések

Használja ezt a túlterhelést, ha a BindingManagerBase kívánt útvonal nem igényel navigációs útvonalat. Ha például a BindingManagerBase rendszer olyan objektumok készletét Binding kezeli, amelyek egy vagy ArrayList több objektumot használnakDataTableDataSource, nincs szükség navigációs útvonalra.

Note

A Item[] tulajdonság mindig egy BindingManagerBase, és soha nem ad vissza null.

Tekintse meg a Binding lehetséges adatforrások listáját, valamint a vezérlők és adatforrások közötti kötések létrehozásával kapcsolatos információkat.

Lásd még

A következőre érvényes: