BindingContext.Item[] Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene un BindingManagerBaseobjeto .
Sobrecargas
| Nombre | Description |
|---|---|
| Item[Object, String] |
Obtiene un objeto BindingManagerBase asociado al origen de datos y al miembro de datos especificados. |
| Item[Object] |
Obtiene el objeto BindingManagerBase asociado al origen de datos especificado. |
Item[Object, String]
Obtiene un objeto BindingManagerBase asociado al origen de datos y al miembro de datos especificados.
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; }
member this.Item(obj * string) : System.Windows.Forms.BindingManagerBase
Default Public ReadOnly Property Item(dataSource As Object, dataMember As String) As BindingManagerBase
Parámetros
- dataSource
- Object
Origen de datos asociado a un determinado BindingManagerBase.
- dataMember
- String
Ruta de navegación que contiene la información que se resuelve en un específico BindingManagerBase.
Valor de propiedad
BindingManagerBase para el origen de datos y el miembro de datos especificados.
Excepciones
El especificado dataMember no existe en el origen de datos.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar para recuperar para Item[]BindingManagerBase un enlace determinado. También muestra cómo controlar el BindingComplete evento para BindingManagerBase asegurarse de que varios controles enlazados al mismo origen de datos permanecen sincronizados cuando se cambia uno de los valores de control. Para ejecutar este ejemplo, pegue el código en un formulario Windows Forms y llame al InitializeControlsAndData método desde el constructor o Load el método de control de eventos del formulario.
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
Comentarios
Use esta sobrecarga cuando BindingManagerBase administra un conjunto de objetos para los que el origen de Binding datos contiene varios objetos. Por ejemplo, un DataSet objeto puede contener varios DataTable objetos vinculados por DataRelation objetos. En tal caso, se requiere la ruta de navegación para permitir que BindingContext devuelva el correcto BindingManagerBase.
Note
La Item[] propiedad siempre devolverá un , BindingManagerBasecuando el dataMember parámetro sea válido. Nunca devolverá null.
Consulte la clase para obtener una lista de posibles orígenes de datos y para obtener información sobre cómo Binding crear enlaces entre controles y orígenes de datos.
Si el deseado BindingManagerBase administra una lista, la ruta de navegación también debe terminar con una lista. Por ejemplo, el siguiente código de C# enlaza un TextBox control a la fecha de pedido en una tabla de pedidos. La ruta de navegación incluye TableName, y RelationName.ColumnName Sin embargo, BindingManagerBase debe recuperarse usando solo y TableNameRelationName (que se resuelve en una lista).
// 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"];
Al devolver un BindingManagerBase, debe usar el mismo origen de datos que y Binding modificar solo la ruta de navegación.
Use el Contains método para determinar si ya existe el deseado BindingManagerBase .
Consulte también
Se aplica a
Item[Object]
Obtiene el objeto BindingManagerBase asociado al origen de datos especificado.
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
Parámetros
- dataSource
- Object
Origen de datos asociado a un determinado BindingManagerBase.
Valor de propiedad
para BindingManagerBase el origen de datos especificado.
Ejemplos
En el ejemplo de código siguiente se devuelven tres BindingManagerBase objetos: uno para un DataView, uno para ArrayListy otro para el DataSource de un Binding objeto que pertenece a un TextBox control .
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
Comentarios
Use esta sobrecarga si BindingManagerBase no necesita una ruta de navegación. Por ejemplo, si BindingManagerBase administra un conjunto de Binding objetos que usan ArrayList o DataTable como DataSource, no se requiere ninguna ruta de navegación.
Note
La Item[] propiedad siempre devolverá un BindingManagerBasey nunca devolverá null.
Consulte la clase para obtener una lista de posibles orígenes de datos y para obtener información sobre cómo Binding crear enlaces entre controles y orígenes de datos.