DataGrid.SetDataBinding(Object, String) Método

Definición

Establece las propiedades DataSource y DataMember en tiempo de ejecución.Sets the DataSource and DataMember properties at run time.

public:
 void SetDataBinding(System::Object ^ dataSource, System::String ^ dataMember);
public void SetDataBinding (object dataSource, string dataMember);
member this.SetDataBinding : obj * string -> unit
Public Sub SetDataBinding (dataSource As Object, dataMember As String)

Parámetros

dataSource
Object

Origen de datos del control DataGrid.The data source for the DataGrid control.

dataMember
String

Cadena DataMember que especifica la tabla a la que se va a enlazar dentro del objeto devuelto por la propiedad DataSource.The DataMember string that specifies the table to bind to within the object returned by the DataSource property.

Excepciones

Uno o varios argumentos no son válidos.One or more of the arguments are invalid.

El argumento dataSource es null.The dataSource argument is null.

Ejemplos

En el ejemplo de código siguiente se establece el DataSource y DataMember en un DataSety un DataTable en el DataSet, respectivamente.The following code example sets the DataSource and DataMember to a DataSet, and a DataTable in the DataSet, respectively.

private:
   void BindControls()
   {
      // Creates a DataSet named SuppliersProducts.
      DataSet^ SuppliersProducts = gcnew DataSet( "SuppliersProducts" );
      // Adds two DataTable objects, Suppliers and Products.
      SuppliersProducts->Tables->Add( gcnew DataTable( "Suppliers" ) );
      SuppliersProducts->Tables->Add( gcnew DataTable( "Products" ) );
      // Insert code to add DataColumn objects.
      // Insert code to fill tables with columns and data.
      // Binds the DataGrid to the DataSet, displaying the Suppliers table.
      dataGrid1->SetDataBinding( SuppliersProducts, "Suppliers" );
   }
private void BindControls(){
    // Creates a DataSet named SuppliersProducts.
    DataSet SuppliersProducts = new DataSet("SuppliersProducts");
    // Adds two DataTable objects, Suppliers and Products.
    SuppliersProducts.Tables.Add(new DataTable("Suppliers"));
    SuppliersProducts.Tables.Add(new DataTable("Products"));
    // Insert code to add DataColumn objects.
    // Insert code to fill tables with columns and data.
    // Binds the DataGrid to the DataSet, displaying the Suppliers table.
    dataGrid1.SetDataBinding(SuppliersProducts, "Suppliers");
 }
   
Private Sub BindControls()
    ' Create a DataSet named SuppliersProducts.
    Dim SuppliersProducts As New DataSet("SuppliersProducts")
    ' Adds two DataTable objects, Suppliers and Products.
    SuppliersProducts.Tables.Add(New DataTable("Suppliers"))
    SuppliersProducts.Tables.Add(New DataTable("Products"))
    ' Insert code to add DataColumn objects.
    ' Insert code to fill tables with columns and data.
    ' Binds the DataGrid to the DataSet, displaying the Suppliers table.
    dataGrid1.SetDataBinding(SuppliersProducts, "Suppliers")
End Sub

Comentarios

Debe utilizar el método SetDataBinding en tiempo de ejecución para restablecer la propiedad DataSource.You must use the SetDataBinding method at run time to reset the DataSource property.

Vea la propiedad DataSource para obtener más detalles sobre la configuración de un origen de datos válido.See the DataSource property for more details about setting a valid data source.

Puede crear una cuadrícula que permita a los usuarios editar datos pero les impide agregar nuevas filas utilizando un DataView como origen de datos y estableciendo la propiedad AllowNew en false.You can create a grid that enables users to edit data but prevents them from adding new rows by using a DataView as the data source and setting the AllowNew property to false. Cuando el DataSource es un DataView o DataTable, establezca la DataMember en una cadena vacía ("").When the DataSource is a DataView or DataTable, set the DataMember to an empty string ("").

Se aplica a

Consulte también: