DataGrid.SetDataBinding(Object, String) Método

Definición

Establece las propiedades DataSource y DataMember en tiempo de ejecución.

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.

dataMember
String

Cadena DataMember que especifica la tabla a la que se va a enlazar dentro del objeto devuelto por la propiedad DataSource.

Excepciones

Uno o varios argumentos no son válidos.

El argumento dataSource es null.

Ejemplos

En el ejemplo de código siguiente se establece y DataSourceDataMember en y DataSeten , y en DataTableDataSet, respectivamente.

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 usar el SetDataBinding método en tiempo de ejecución para restablecer la DataSource propiedad .

Consulte la DataSource propiedad para obtener más información sobre cómo establecer un origen de datos válido.

Puede crear una cuadrícula que permita a los usuarios editar datos, pero evitar que agreguen nuevas filas mediante un DataView como origen de datos y establecer la AllowNew propiedad falseen . DataSource Cuando es o DataViewDataTable, establezca en DataMember una cadena vacía ("").

Se aplica a

Consulte también